I want to control servo motor with keypad 4x4.
Want to start continous loop on pressing particular button till another button is pressed for another continous loop.
I m new to programming and managed to cut copy and edit code for the same.
Problem is my code is verified on IDE and uploaded on adruino uno but not working.
#include <Servo.h>
Servo leftRightservo;
#include <Keyboard.h>
#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
{'4', '5', '6', 'B'},
{'1', '2', '3', 'A'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
boolean backHandRun = false; // NEW
boolean foreHandRun = false; // NEW
void setup() {
leftRightservo.attach(10);
int position = 0;
Serial.begin(9600);
}
void loop() {
char key = customKeypad.getKey();
Serial.println(key);
if (key) // Check for a valid key.
{
switch(key) {
case '1': // Back Hand
Serial.println("Back Hand Active");
backHandRun = true; // NEW
foreHandRun = false; // NEW
break;
case '2': // forehand
Serial.println("Fore hand active");
backHandRun = false; // NEW
foreHandRun = true; // NEW
break;
}
delay(10);
}
}
void foreHand() { // I want this to loop until i press a button on the remote
if (foreHandRun == true) { // new
leftRightservo.write(10);
delay(100);
leftRightservo.write(50);
delay(100);
leftRightservo.write(100);
delay(100);
}
}
void backHand() { // I want this to loop until i press a button on the remote
if (backHandRun == true) { // new
leftRightservo.write(90);
delay(100);
leftRightservo.write(180);
delay(100);
}
}
only servo motor initialize and doesnt move on pressing button.
Help me