Hi all,
I've been working with the Arduino code. It seems different than just normal C. I have a normal hobby servo setup and it's working well. I would like to insert a switch in the loop code that will allow me to start and stop the loop(on and off). In the past I've used a goto end statment, but that was years ago and I'm still learning to write code. When I try to compile it, it gives me an error of "error: 'end' was not declared in this scope" This is just a copy paste of the servo code from Ardiuno website with some changes for the switch.
Is there something better I can use? Thanks for your help.
The code is as follows:
#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
int switchPin = 2; // start stop switch
int val2 = 0; // variable to read the value from the start/stop pin
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(switchPin, INPUT); // declare switch as input
}
void loop(){
val2 = digitalRead(switchPin); // read input value of switch
if (val2 == HIGH) { // check the switch position
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 179); // 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(0 ); } // waits for the servo to get there
if (val2 == LOW); { // check the switch position
goto end; // skips over the servo code and goes to end, then repeats
}
end;
}