Advertisement
Guest User

Untitled

a guest
Dec 27th, 2014
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. void loop() {
  2. if(Serial.available()>0){
  3. int value = Serial.read()-'0'; //e um sistema binário em que o valor indicado influencia duty-cycle, 0- e o valor previsto, 1- e o valor subtraído por 10.
  4. dutyCycle=value*10; // o duty é em percentagem
  5. Serial.println(dutyCycle);
  6. }
  7. cicloonoffwithdelay(1000,dutyCycle);
  8. }
  9. //Esta função gera uma onda quadrada
  10. //Parâmetros: A frequência e o dutycycle da onda
  11.  
  12. void cicloonoffwithdelay(int frequency, int dutyCycle) { //usamos o ciclo com delay ao contrário da pergunta 13
  13. long T;
  14. T=1000000/frequency;
  15. long Ton;
  16. Ton=dutyCycle*T/100;
  17. long Toff=T-Ton;
  18.  
  19. digitalWrite(pin, HIGH);
  20. delayMicroseconds(Ton);
  21. digitalWrite(pin, LOW);
  22. delayMicroseconds(Toff);
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement