Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include <Servo.h>
  2. const float GRAUS=0.25;// equivale a 1 min;
  3. //const float GRAUS=5; // equivale a 20 min
  4.  
  5. Servo servo;
  6. int pinServo = 10;
  7. float pos=0; // em graus
  8. int leitura_hora;
  9. int leitura_min;
  10. float graus_leitura;
  11. int volta=0;
  12.  
  13. void setup() {
  14. Serial.begin(9600);
  15. servo.attach(pinServo);
  16. servo.write(pos);
  17. }
  18.  
  19. void loop() {
  20. Serial.print("Informe a hora e a quantidade de minutos, respectivamente: ");
  21. while(Serial.available()==0){};
  22. while(Serial.available()){
  23. leitura_hora = Serial.parseInt();
  24. leitura_min = Serial.parseInt();
  25. volta++;
  26.  
  27. if(volta==2){ // sempre lia depois um '0'. Esse if é para evitar isso.
  28. volta=0;
  29. break;
  30. }
  31.  
  32. Serial.print(leitura_hora);
  33. Serial.print(" ");
  34. Serial.println(leitura_min);
  35.  
  36. graus_leitura = (leitura_hora * 15) + (leitura_min*0.25) ;
  37.  
  38. Serial.println(pos);
  39. Serial.println(graus_leitura);
  40. for(pos=graus_leitura; pos<=180; pos+=GRAUS){
  41. servo.write(pos);
  42. Serial.println(pos);
  43.  
  44. // delay(60000); //se for usar GRAUS=0.25
  45. //delay(60000*20); //se for usar GRAUS = 20;
  46. delay(500); //apenas para teste
  47. }
  48. Serial.println(pos);
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement