// Servo w/ RaspberryPi GPIO control // // Setup: - Wire Pi GPIO control pin to Arduino digital pin 5 // GPIO +5v to "Vin" to power Arduino from Pi // Wire Pi +5v and Gnd to breadboard for power to Arduino // // - Connect a servo to +, gnd and digital pin 6 // ----------------------------------------------------------- #include int pos = 0; // variable to store the servo position int piGPIO; // variable for state of switch int servoPin = 6; // variable for servo pin number Servo myservo; // create servo object to control a servo // twelve servo objects can be created on most boards void setup() { myservo.attach(servoPin); // attaches the servo on pin 6 to the servo object pinMode(5, INPUT); // Sets digital pin 5 for input (getting HIGH or LOW from Pi GPIO) } void loop() { piGPIO = digitalRead(5); if(piGPIO == LOW){ // If switch is closed (pin connected to ground) myservo.write(180); // tell servo to go to position 180 delay(10); // delay to read LCD characters } else { myservo.write(10); // tell servo to go to position 0 delay(10); // delay to read LCD characters } }