harshsin

Transmitter

Apr 14th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.46 KB | None | 0 0
  1. #include <Servo.h>
  2. Servo myServo;
  3. int state=2;
  4. void setup() {
  5.   myServo.attach(9);
  6.   pinMode(10,OUTPUT);  
  7.   Serial.begin(9600);
  8. }
  9. void loop() {
  10.  if(Serial.available() > 0){ // Checks whether data is coming from the serial port
  11.     state = Serial.read(); // Reads the data from the serial port
  12.  }
  13.  if(state==0){
  14.   digitalWrite(10,HIGH);
  15.   myServo.write(40);
  16.   }
  17.   if(state==1){
  18.   digitalWrite(10,LOW);
  19.   myServo.write(10);
  20.   }
  21.  Serial.println(state);
  22. }
Add Comment
Please, Sign In to add comment