Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- const float GRAUS=0.25;// equivale a 1 min;
- //const float GRAUS=5; // equivale a 20 min
- Servo servo;
- int pinServo = 10;
- float pos=0; // em graus
- int leitura_hora;
- int leitura_min;
- float graus_leitura;
- int volta=0;
- void setup() {
- Serial.begin(9600);
- servo.attach(pinServo);
- servo.write(pos);
- }
- void loop() {
- Serial.print("Informe a hora e a quantidade de minutos, respectivamente: ");
- while(Serial.available()==0){};
- while(Serial.available()){
- leitura_hora = Serial.parseInt();
- leitura_min = Serial.parseInt();
- volta++;
- if(volta==2){ // sempre lia depois um '0'. Esse if é para evitar isso.
- volta=0;
- break;
- }
- Serial.print(leitura_hora);
- Serial.print(" ");
- Serial.println(leitura_min);
- graus_leitura = (leitura_hora * 15) + (leitura_min*0.25) ;
- Serial.println(pos);
- Serial.println(graus_leitura);
- for(pos=graus_leitura; pos<=180; pos+=GRAUS){
- servo.write(pos);
- Serial.println(pos);
- // delay(60000); //se for usar GRAUS=0.25
- //delay(60000*20); //se for usar GRAUS = 20;
- delay(500); //apenas para teste
- }
- Serial.println(pos);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement