The Wiring servo motor library allows for easily manipulating a standard servo motor connected to a pin.
In the following Wiring code, when the character called “1″ is received, the Wiring board commands the motor to move to a different position, thus moving the ‘finger’ down.
Wiring concepts in this recipe:
Digital output
Simple serial communication (input)
Controling a servo motor from Wiring
The Wiring servo motor library
BEFORE YOU START, make sure that that the Wiring environment is correctly installed on your computer.
BEFORE YOU START, connect the USB cable to the Wiring board and your computer.
Working with the Wiring code of this recipe
Bridge page ‘For more detailed instructions, see the “Export Wiring Code Guide”‘
Click inside the text box below, select the entire code content (use the ‘Select All’ command) and copy
Open the Wiring environment and create a new “Sketch” (File > New)
Paste the code into the new Sketch
Verify the code (the “Verify” key on the left)
Reset the Wiring board
Export the code to the Wiring board (File > Export to Board)
Wait for the “Success” message; then reset the Wiring board again
Wiring Code:
// StubbornFinger
// ----------------------------------------------------------
// InstantSOUP 2004
// http://instantsoup.interaction-ivrea.it
// ----------------------------------------------------------
//
//
char val; // variable to receive data from the serial port
int myservo = 0; // servo channel to attach a servo.
int pos = 90; // variable to keep the servo position
int servopin = 0; // digital pin 0 used to connect the servo
void setup()
{
beginSerial(19200); // initialize serial port
beginServo(); // initializes the servo library
attachServo(myservo, servopin);
servoWrite(myservo, 90);
}
void serialEvent()
{
val = serial; // get data received in val
}
void loop() {
if(val == '1') //
{
delay(10); // waits for 1 millisecond
servoWrite(myservo, 90);
delay(300);
servoWrite(myservo, 120);
delay(300); // waits for the servo to reach the position
servoWrite(myservo, 90);
delay(300);
val ='0';
}
}
// ----------------------------------------------------------
GO TO TASK 3: PUBLISH THE FLASH CODE