I'm having trouble making the if statement (first line of the void loop) to work. When I upload the program it renders it as true constantly. I am using a button and receiver to send an input to digital pin 3 but it seems it doesn't matter if I hook up the receiver or not. Any help would be greatly appreciated.
#include <MeccaBrain.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *leftLeg = AFMS.getMotor(2 );
Adafruit_DCMotor *rightLeg = AFMS.getMotor(1);
void setup() {
pinMode(3, INPUT);
AFMS.begin();
leftLeg->setSpeed(150);
leftLeg->run(RELEASE);
rightLeg->setSpeed(150);
rightLeg->run(RELEASE);
pinMode(chainPin1, OUTPUT);
pinMode(chainPin2, OUTPUT);
pinMode(chainPin3, OUTPUT);
Serial.begin(9600);
//"Discover" all the modules (make them blue-colored instead of green-colored)
//for some unknown reason, I have to repeat it from time to time
for (int i = 0; i < 50; i++)
{
chain1.communicate();
chain2.communicate();
chain3.communicate();
}
//delay to be sure that all modules are ready
//if some module is "not discovered" than it will remain green and later this module will behave strangely
delay(2000);
}
void loop() {
if (digitalRead(3) == HIGH)
{
leftLeg->run(BACKWARD);
rightLeg->run(BACKWARD);
delay(5000);
leftLeg->run(RELEASE);
rightLeg->run(RELEASE);
delay(1000);
setJoint(RIGHT_ARM_PITCH, 150);
delay(500);
setJoint(RIGHT_ARM_ROLL, 220);
delay(500);
setJoint(RIGHT_ARM_ELBOW, 190);
delay(4000);
setJoint(RIGHT_ARM_PITCH, 0);
delay(500);
setJoint(RIGHT_ARM_ROLL, 160);
delay(500);
setJoint(RIGHT_ARM_ELBOW, 130);
delay(2000);
leftLeg->run(FORWARD);
rightLeg->run(BACKWARD);
delay(2500);
leftLeg->run(RELEASE);
rightLeg->run(RELEASE);
delay(1000);
leftLeg->run(FORWARD);
rightLeg->run(FORWARD);
delay(5000);
leftLeg->run(RELEASE);
rightLeg->run(RELEASE);
delay(1000);
delay(10000);
}
else
{
}
}