I opted to just using the whole keypad.
Also, I used your suggestion to create a function to control the commands for when I press a specific button on the keypad. I haven't been able to test it out yet today since I'm currently out of town. The sketch compiled; but, my question is:
According to my current sketch, is the logic correct in terms of what I want it to do?
In other words, I want it so when I press '*' on the key pad, the servo will run as long as I hold it.
#include <Servo.h>
#include <Keypad.h>
#include <BMSerial.h>
#include <RoboClaw.h>
#define address 0x80
// Keypad Stuff
const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns
// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'#','0','*'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 3, 4, 5, 6 };
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 0, 1, 2 };
// Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
// Joypad Buttons
const int upA = 7;
const int downA = 8;
const int upB = 12;
const int downB = 13;
// Servo stuff
Servo myservo; // Create servo object to control servo
int pos = 90; // Variable to store the servo position
// RoboClaw stuff
RoboClaw roboclaw(5,6);
int mSpeed = 64;
// HSR-1425CR controls
void buttonstarpressed ()
{
while (kpd.getKey() == '*')
{
for(pos; pos < 180; pos += 1) // Begin to rotate pressure washer from rest to full power
{
myservo.write(pos);
// Delay increase in “angle” by 10 ms before going through loop again
delay(10);
}
} // wait for release
myservo.write(90);
}
void buttonpoundpressed ()
{
while (kpd.getKey() == '#')
{
for(pos; pos > 0; pos -= 1) // Begin to rotate pressure washer from rest to full power
{
myservo.write(pos);
// Delay increase in “angle” by 10 ms before going through loop again
delay(10);
}
}
myservo.write(90);
}
void setup()
{
pinMode(upA, INPUT);
pinMode(downA, INPUT);
pinMode(upB, INPUT);
pinMode(downB, INPUT);
myservo.attach(11); // “Attaches” HSR1425CR servo on pin 11
myservo.write(pos); // Initially set servo motor to zero movement (“90 degrees”)
// Full power in direction 1: “0 degrees”
// Full power in direction 2: “180 degrees”
Serial.begin(2400);
}
void loop()
{
char key = kpd.getKey();
// RoboClaw control
if(digitalRead(upA) == LOW)
{
roboclaw.ForwardM1(address, mSpeed);
}
if(digitalRead(downA) == LOW)
{
roboclaw.BackwardM1(address, mSpeed);
}
if(digitalRead(upB) == LOW)
{
roboclaw.ForwardM2(address, mSpeed);
}
if(digitalRead(downB) == LOW)
{
roboclaw.BackwardM2(address, mSpeed);
}
}