Here is my objective:
If the value of EMGv
is at or above 900, start moving the motors left. The motors should continue to move left for a maximum of one second, provided EMGv
stays at or above 900. If during this time EMGv
goes below 900, the motors should move right for one second. Then the motors should stop. At any time after this should EMGv
go above 900 again, the process should repeat.
In simpler terms, the project is a robotic hand, wired to an EMG circuit. When the EMG signal gets above 900 the hand should close by the motors all turning left for one second and when the signal goes below 900 the hand should open by the motors turning right for one second.
Here is my loop atm when move(motor #, speed, direction (1 for left, 0 for right))
is the function to move the motors and stop()
stops all motors
void loop(){
unsigned long starttime; //time limit for hand movement
int EMGv = analogRead(EMG);
starttime=millis();
while(EMGv >= 900){
if (millis()-starttime < 1000) //limit on 1000ms
{
move(0, 255, 1); //motor 1, full speed, left
move(1, 255, 1); //motor 2, full speed, left
move(2, 255, 1); //motor 3, full speed, left
move(3, 255, 1); //motor 4, full speed, left
move(4, 255, 1); //motor 5, full speed, left
} else {
stop();
}
}
}