Hi every one
I'm trying to control servo via keypad In order to determine the angle (position)
i want to input angle(position) by keypad
for example 120 then press # it will move to mentioned position
code as following :
#include "Keypad.h"
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
char pos = 0; // variable to store the servo position
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] =
{{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}};
byte rowPins[ROWS] = {
5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {
8, 7, 6}; //connect to the column pinouts of the keypad
int count=0;
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup()
{
Serial.begin(9600);
}
void loop()
{
char key = keypad.getKey();
if (key != NO_KEY)
{
pos = key;
//Serial.print(key);
if (key == '#')
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(20);
Serial.print(pos);
}
}
}