This code:
#include <Servo.h>
Servo Servo1; // creates an object for each servo
Servo Servo2;
Servo Servo3;
Servo Servo4;
Servo Servo5;
Servo Servo6;
const int buttonPin = 7; // declares pin for the Quickstart button
const int potpinS1 = A0; //analog input pin A0
const int potpinS2 = A1; //analog input pin A0
const int potpinS3 = A2; //analog input pin A0
const int potpinS4 = A3; //analog input pin A0
const int potpinS5 = A4; //analog input pin A0
const int potpinS6 = A5; //analog input pin A0
int newvalS1, oldvalS1;
int newvalS2, oldvalS2;
int newvalS3, oldvalS3;
int newvalS4, oldvalS4;
int newvalS5, oldvalS5;
int newvalS6, oldvalS6;
int buttonState = 0;
int range = 2;
boolean quickstartOn = false;
int quickstartTime = 0;
void setup()
{
Serial.begin(9600); //For debugging
Servo1.attach(13);
Servo2.attach(12);
Servo3.attach(11); //assigning each servo a pin
Servo4.attach(10);
Servo5.attach(9);
Servo6.attach(8);
while(quickstartTime < 6) { //if the quickstart button is pressed when the system turns on, skip the delays and serial readouts
quickstartTime + 0.01;
if(digitalRead(buttonPin == HIGH)){
quickstartTime +6;
goto quickstart;
}
delay(1);
}
Serial.println("Man and Robot, Walk alike");
Serial.println("]---------------------------------------------------------------------------[");
Serial.println("Project by Kyle Sowry in Room 54");
Serial.println("Bipedal robot controlled by a pair of pants");
Serial.println("In the serial monitor, you can read the values being sent to the servos");
Serial.println(" Servos 5/6 |=|----|=| ");
Serial.println(" | | | | ");
Serial.println(" | | | | ");
Serial.println(" | | | | ");
Serial.println(" Servos 3/4 (=| |=) ");
Serial.println(" | | | | = is a servo ");
Serial.println(" | | | | ");
Serial.println(" | | | | ");
Serial.println(" | | | | ");
Serial.println(" Servos 1/2 |=| |=| ");
Serial.println(" ___|_| |_|___ ");
Serial.println("");
Serial.println("Upon start, try to keep a straight leg to begin with and slowly move joints to test");
Serial.println("]---------------------------------------------------------------------------[");
delay(5000);
Serial.println("Testing in:");
delay(1000);
Serial.println("5");
delay(1000);
Serial.println("4");
delay(1000);
Serial.println("3");
delay(1000);
Serial.println("2");
delay(1000);
Serial.println("1");
delay(1000);
quickstart:
}
void loop()
{
newvalS1 = analogRead(potpinS1); //set "newval" for each servo/sensor to equal the reading from the flex sensors
newvalS2 = analogRead(potpinS2);
newvalS3 = analogRead(potpinS3);
newvalS4 = analogRead(potpinS4);
newvalS5 = analogRead(potpinS5);
newvalS6 = analogRead(potpinS6);
newvalS1 = map(newvalS1, 300, 600, 0, 179); //map each "newval" to an appropriate reading for the flex sensor
newvalS2 = map(newvalS2, 300, 600, 0, 179);
newvalS3 = map(newvalS3, 300, 600, 0, 179);
newvalS4 = map(newvalS4, 300, 600, 0, 179);
newvalS5 = map(newvalS5, 300, 600, 0, 179);
newvalS6 = map(newvalS6, 300, 600, 0, 179);
if (newvalS1 < (oldvalS1-range) || newvalS1 > (oldvalS1+range)){ // From here onward is a series of calculations that do an important job: keep the servos still while the flex sensors are not moving. It reduces noise picked up along the cable.
if(quickstartOn == false) { // This statement find out if the quickstart button was pressed at the beginning. if it wasn't, the serial info will be sent. if the button was pressed, the data will not be sent. this is because sending serial data takes up the most time in the Arduino's processing, which can slow down the servo updating and make it jittery
Serial.print("1- ");
Serial.println(newvalS1);
oldvalS1=newvalS1;
Servo1.write(newvalS1);
}else{
oldvalS1=newvalS1;
Servo1.write(newvalS1);
}
if (newvalS2 < (oldvalS2-range) || newvalS2 > (oldvalS2+range)){
if(quickstartOn == false) {
Serial.print("2- ");
Serial.println(newvalS1);
oldvalS2=newvalS2;
Servo2.write(newvalS2);
}else{
oldvalS2=newvalS2;
Servo2.write(newvalS2);
}
if (newvalS3 < (oldvalS3-range) || newvalS3 > (oldvalS3+range)){
if(quickstartOn == false) {
Serial.print("3- ");
Serial.println(newvalS3);
oldvalS3=newvalS3;
Servo3.write(newvalS3);
}else{
oldvalS3=newvalS3;
Servo3.write(newvalS3);
}
if (newvalS4 < (oldvalS4-range) || newvalS4 > (oldvalS4+range)){
if(quickstartOn == false) {
Serial.print("4- ");
Serial.println(newvalS4);
oldvalS4=newvalS4;
Servo4.write(newvalS4);
}else{
oldvalS4=newvalS4;
Servo4.write(newvalS4);
}
if (newvalS5 < (oldvalS5-range) || newvalS5 > (oldvalS5+range)){
if(quickstartOn == false) {
Serial.print("5- ");
Serial.println(newvalS5);
oldvalS5=newvalS5;
Servo1.write(newvalS5);
}else{
oldvalS5=newvalS1;
Servo1.write(newvalS5);
}
if (newvalS6 < (oldvalS6-range) || newvalS6 > (oldvalS6+range)){
if(quickstartOn == false) {
Serial.print("6- ");
Serial.println(newvalS6);
oldvalS6=newvalS6;
Servo1.write(newvalS6);
}else{
oldvalS6=newvalS6;
Servo6.write(newvalS6);
}
delay(2); //slow down looping for easier serial debug and less jitter. Delay can be increased or decreased depending on servo.
}
}
is getting an error. compile it and find it. I cant seem to it.
any ideas?
help would be appreciated