#include <Keypad.h>
#include <Servo.h>
#define servo_delta_var 10
#define base_minimo 0
#define base_maximo 180
const byte ROWS = 4; // four rows
const byte COLS = 4; // four columns
// define os valores para cada botao do teclado
char hexaKeys[ROWS][COLS]={ {'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'} };
// connect to the column pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; // Pins connected to C1, C2, C3, C4
// connect to the row pinouts of the keypad
byte rowPins[ROWS] = {13, 12, 8 ,7}; // Pins connected to R1, R2, R3, R4
// initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap (hexaKeys), rowPins, colPins, ROWS, COLS);
signed int atraso;
Servo servo_base;
int servo_base_pin=10;
signed int angulo_base;
void setup(){
Serial.begin(9600);
servo_base.attach(servo_base_pin);
angulo_base = 90;
atraso = 50;
}
void loop(){
char valorChave = customKeypad.getKey();
switch (valorChave){
case '4' : if (angulo_base<base_maximo) {
angulo_base += servo_delta_var;
Serial.print(valorChave);
Serial.print(" : ");
Serial.println(angulo_base);
}
break;
case '6' : if (angulo_base>base_minimo) {
angulo_base -= servo_delta_var;
Serial.print(valorChave);
Serial.print(" : ");
Serial.println(angulo_base);
}
break;
}
servo_base.write(angulo_base);
delay(atraso);
}