Advertisement
RuiViana

PWM Variavel Freq e Duty

Jul 15th, 2015
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2. #include <TimerOne.h>
  3. #define botao_incremento A0
  4. #define botao_decremento A1
  5. #define botao_frequencia_incremento A2
  6. #define botao_frequencia_decremento A3
  7. unsigned long freq;
  8. unsigned int dspduty;
  9. unsigned int duty;
  10. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  11. // ------------------------------------ setup -------------------------------
  12. void setup()
  13. {
  14. Serial.begin(9600);
  15. lcd.begin(16,2);
  16. lcd.print("BEM VINDOS");
  17. pinMode(A0, INPUT);
  18. pinMode(A1, INPUT);
  19. pinMode(A2, INPUT);
  20. pinMode(A3, INPUT);
  21. pinMode(9, OUTPUT);
  22. }
  23. // ------------------------------------ loop -------------------------------
  24. void loop()
  25. {
  26.  
  27. lcd.print (" ");
  28. lcd.setCursor(0,1);
  29. Timer1.initialize(freq);
  30. Timer1.pwm(9, duty);
  31. delay(100);
  32. if(digitalRead(botao_frequencia_incremento) == HIGH)
  33. {
  34. freq = freq +1000;
  35. // Serial.println(freq);
  36. delay(500);
  37. }
  38. if(digitalRead(botao_frequencia_decremento)== HIGH)
  39. {
  40. freq = freq -1000;
  41. // Serial.println(freq);
  42. delay(500);
  43. }
  44. lcd.print (" ");
  45. lcd.setCursor(0,1);
  46. if(digitalRead(botao_incremento) == HIGH)
  47. {
  48. duty = duty +500;
  49. delay(500);
  50. }
  51. if(digitalRead(botao_decremento) == HIGH)
  52. {
  53. duty = duty -500;
  54. delay(500);
  55. }
  56. // Serial.println(duty);
  57. dspduty = map(duty,0 ,65535,0, 100);
  58. Serial.println(dspduty);
  59. lcd.print(dspduty);
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement