Guest User

Untitled

a guest
May 26th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <Servo.h>
  2.  
  3. Servo servo_pin_7;
  4. void setup(){
  5.   Serial.begin(9600);   //start the serial communication
  6.  servo_pin_7.attach(7);    
  7. }
  8.  
  9. void loop(){
  10.  
  11.   if(Serial.available() > 0){           //if some data is available of in the serial port
  12.     char state = Serial.read();   //read the value
  13.     if(state == '0'){             //if statement will be true(1)
  14.        servo_pin_7.write( 0 );
  15.     }
  16.     if(state == '1'){             //if statement will be false(0)
  17.        servo_pin_7.write( 45 );
  18.     }
  19.      if(state == '2'){             //if statement will be true(1)
  20.        servo_pin_7.write( 90 );
  21.     }
  22.      if(state == '3'){             //if statement will be true(1)
  23.        servo_pin_7.write( 180 );
  24.     }
  25.   }
  26. }
Add Comment
Please, Sign In to add comment