The purpose of this project is to associate different servos with different key presses and have the servos turn completely (180 degrees) upon a key press. I keep getting the error message:
"exit status 1
a function-definition is not allowed here before '{' token"
whenever I try to verify the code. Can anyone see why this error code is appearing? Code is inserted below in this message. Thank you all very much.
void setup() {
#include <Servo.h>
Servo pinky;
Servo ring;
Servo middle;
Servo index;
Servo thumb;
Servo wrist;
char val;
int ppos = 0;
int rpos = 0;
int mpos = 0;
int ipos = 0;
int tpos = 0;
int wpos = 180;
void setup()
{
//Show which servo is connected to which pin
pinky.attach(6);
ring.attach(5);
middle.attach(4);
index.attach(3);
thumb.attach(2);
wrist.attach(6);
//set all servos to starting position
pinky.write(0);
ring.write(0);
middle.write(0);
index.write(0);
thumb.write(0);
wrist.write(180);
Serial.begin(9600); //start serial output at 9600
Serial.println("WE WORK!!");
}
void loop()
{
if (val == 'y') {
//rotate wrist counter clockwise
wpos = 0;
wrist.write(wpos);
}
if (val == 'h') {
//rotate wrist clockwise
wpos = 200;
wrist.write(wpos);
}
if (val == 'c') {
//close whole hand
ppos = 180;
pinky.write(ppos);
ring.write(ppos);
middle.write(ppos);
index.write(ppos);
thumb.write(ppos);
}
if (val == 'o') {
//open whole hand
ppos = 0;
pinky.write(ppos);
ring.write(ppos);
middle.write(ppos);
index.write(ppos);
thumb.write(ppos);
}
}
}