Hey everyone, I tried watching every YT vid on the toggling of the pushbutton, in Arduino. I read through this forum seeking an answer, but no luck.
It's worth mentioning that I'm an absolute beginner and I've been stuck with it for a couple of weeks.
This is my problem: I manage to control my two servos with EMG signals from my muscles.
The thing I can't figure out is how to create a START/STOP feature in the code. When pressed to START, servos react to EMG. When pressed STOP they go in a certain position.
Below is code I was able to patch up. I know I'm missing buttonState and all, but don't know what to fit where.
#include <Servo.h>
#define BTN 4
Servo myServo;
Servo myServo1;
int EMG, EMG1; // Create a variable called EMG
int ServoPin = 6;
int ServoPin1 = 2;
int angle, angle1; // Create a variable called ServoPin
void setup() {
myServo.attach(ServoPin);
myServo1.attach(ServoPin1);
pinMode(BTN, INPUT);
}
void loop() {
if () {
myServo.write(80);
myServo1.write(50);
}
else if (){
EMG = analogRead(A0); // Read from Analog port 0 and copy the value to EMG
angle = map(EMG, 300, 800, 70, 100);
myServo.write(angle);
EMG1 = analogRead(A1);
angle1 = map(EMG1, 200, 700, 40, 80);
myServo1.write(angle1);
}
}
Any help is incredibly appreciated!!!