Advertisement
makispaiktis

Arduino - Στροφή Servo κατά όρισμα που δίνεται από console

Apr 16th, 2019 (edited)
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Servo.h>
  2. Servo servida;
  3.  
  4.  
  5.  
  6. void setup() {
  7.   // put your setup code here, to run once:
  8.   Serial.begin(9600);
  9.   servida.attach(3);
  10.  
  11. }
  12.  
  13. void loop() {
  14.   // put your main code here, to run repeatedly:
  15.   //int counter = 0;
  16.   int number = 0;
  17.  
  18.   while (true) {
  19.      
  20.      
  21.  
  22.     if(Serial.available()) {
  23.       char c = Serial.read();
  24.       if(c == '\n') {
  25.         break;  //otan teleiwsei to noumero vgainoyme apo to loop
  26.       }
  27.       else {
  28.         number = number * 10;
  29.         number += (c - '0');
  30.       }
  31.     }
  32.   }
  33.  
  34.   Serial.println(number);
  35.   servida.write(number);
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement