Good day
Will the following code work to control a servo conected to Digital Pin9?
I am planning to copy the C++ Button & create another button, but just changing the value sent to '00'.
/*
* Serial Read Servo
* -----------------
* Moves a Servo connected to digital pin 9.
* The Servo will move the number given by a
* ASCII number read from the serial port.
* One Servo with two buttons (Pan Left & Pan Right)
* Created 10 March 2011
*/
int Servo1 = 9; // select the pin for Servo1
int val = 0; // variable to store the data from the serial port
void setup() {
pinMode(Servo1,OUTPUT); // declare Servo1 pin as output
Serial.begin(9600); // connect to the serial port
}
void loop () {
val = Serial.read(); // read the serial port
if (val > '0' && val <= '180' ) //Button1 Pan Left represented by a '0'
if (val > '00' && val <= '180' ) //Button2 Pan Right represented by a '00'
val = val - '0'; //Read Value from Button1
val = val - '00'; //Read Value from Button2
for(int i=0; i<val; i++) //Button1 Pan Left
for(int i=00; i<val; i++) //button2 Pan Right
Serial.println("MOVE!"); //message to display in Serial Monitor
digitalWrite(Servo1,val);
delay(15);
}
Feel free to input any sugestions.