User Tools

Site Tools


move_serialread_arduino

MOVEMENT serialread > arduino

#include <Servo.h>
  
Servo emperor; // create servo object

int incomingByte = 0; // for reading incoming serial data
int data = 11; // define data pin
 
void setup() {

  Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
  emperor.attach(data);
  
  }
 
void loop() {
 
  // send data only when you receive data:
  if (Serial.available() > 0) {
  // read the incoming byte:
  incomingByte = Serial.read();

  // turn the servo in the direction of received data:
  // 0-90 spin counter-clockwise
  // 90 stop
  // 90-180 spin clockwise
  emperor.write(incomingByte);
    }
}
move_serialread_arduino.txt · Last modified: 2014/01/23 14:31 by zoza