############################include <Servo.h> Servo myservo; // create servo object to control a servo // int potpin = 0; // analog pin used to connect the potentiometer int val; // variable to read the value from the analog pin char ser; void setup() { Serial.begin(9600); myservo.attach(9); // attaches the servo on pin 9 to the servo object } void loop() { if (Serial.available() > 0) { ser = Serial.read(); } if (ser == '4'){ myservo.write(10); } if (ser == '3'){ myservo.write(30); } if (ser == '2'){ myservo.write(60); } if (ser == '1'){ myservo.write(75); } if (ser == 's'){ myservo.write(150); } // val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023) // scale it to use it with the servo (value between 0 and 180) //myservo.write(val); // sets the servo position according to the scaled value delay(15); // waits for the servo to get there }
Raspberry Pi:
import serial print("press 'f' to go Fast") print("press 'm' to go Medium speed") print("press 's' to Stop") print("press 'q' to quit") print("") print("") ser = serial.Serial('/dev/ttyACM0', 9600) while 1: var = raw_input() if var == 'f': print("Fast") ser.write('a') print("") elif var == 'm': print("Medium") ser.write('b') print("") elif var == 's': print("Stop") ser.write('c') print("") elif var == 'q': print("quitting ......") quit()
No comments:
Post a Comment