#include <LiquidCrystal.h>
#include <Servo.h>
#include <Keypad.h>
const int dirPin1 = 49;
const int stepPin1 = 47;
const int dirPin2 = 53;
const int stepPin2 = 51;
const int stepsPerRevolution = 200;
LiquidCrystal lcd(9, 8, 7, 6, 5, 4);
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
uint8_t colPins[COLS] = { 18, 19, 20, 21 };
uint8_t rowPins[ROWS] = { 14, 15, 16, 17 };
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
char input[4]; // Armazena a entrada do teclado
int inputCount = 0; // Contador para rastrear a entrada
Servo servo1,servo2,servo3,servo4,servo5,servo6;
void setup() {
input[3]='\0';
servo1.attach(10);
servo2.attach(11);
servo3.attach(12);
servo4.attach(13);
servo5.attach(1);
servo6.attach(0);
pinMode(stepPin1, OUTPUT);
pinMode(dirPin1, OUTPUT);
pinMode(stepPin2, OUTPUT);
pinMode(dirPin2, OUTPUT);
Serial.begin(9600);
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Insira uma moeda!");
delay(5000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Escolha o seu ");
lcd.setCursor(0, 1);
lcd.print("pedido: ");
}
void loop() {
char key = keypad.getKey();
if (key != NO_KEY) {
if (key == '#') {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Escolha o seu ");
lcd.setCursor(0, 1);
lcd.print("pedido: ");
inputCount = 0;
} else {
if (inputCount < 3) {
if (inputCount == 0 && (key == 'A' || key == 'B' || key == 'C')) {
input[0] = key;
lcd.print(key);
inputCount++;
} else if (inputCount > 0 && key >= '0' && key <= '9') {
input[inputCount] = key;
lcd.print(key);
inputCount++;
}
}
if (inputCount == 3 && key == '*') {
if(String(input).equals("A12")){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Aguarde");
lcd.setCursor(0, 1);
lcd.print("A processar A12");
andar_posA12();
delay(5000);
}
if(String(input).equals("A23")){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Aguarde");
lcd.setCursor(0, 1);
lcd.print("A processar A23");
andar_posA23();
delay(5000);
}
if(String(input).equals("B45")){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Aguarde");
lcd.setCursor(0, 1);
lcd.print("A processar A45");
andar_posB45();
delay(5000);
}
if(String(input).equals("B56")){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Aguarde");
lcd.setCursor(0, 1);
lcd.print("A processar A56");
andar_posB56();
delay(5000);
}
if(String(input).equals("C78")){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Aguarde");
lcd.setCursor(0, 1);
lcd.print("A processar C78");
andar_posC78();
delay(5000);
}
if(String(input).equals("C89")){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Aguarde");
lcd.setCursor(0, 1);
lcd.print("A processar C89");
andar_posC89();
delay(5000);
}
delay(1000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Retire");
lcd.setCursor(0, 1);
lcd.print(" bebida");
delay(5000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Escolha o seu ");
lcd.setCursor(0, 1);
lcd.print("pedido: ");
inputCount = 0;
}
}
}
}
void andar_posA12(){
digitalWrite(dirPin1, HIGH);
digitalWrite(dirPin2, HIGH);
// Spin motor slowly
for(int x = 0; x < stepsPerRevolution; x++)
{
digitalWrite(stepPin1, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin1, LOW);
delayMicroseconds(2000);
digitalWrite(stepPin2, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin2, LOW);
delayMicroseconds(2000);
}
servo1.write(0); // move the servo to 0 degrees
delay(1000); // wait for 1 second
servo1.write(90); // move the servo to 90 degrees
delay(1000); // wait for 1 second
servo1.write(180); // move the servo to 180 degrees
delay(1000); // wait for 1 second
for(int x = 0; x < stepsPerRevolution; x++)
{
digitalWrite(stepPin1, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin1, LOW);
delayMicroseconds(2000);
digitalWrite(stepPin2, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin2, LOW);
delayMicroseconds(2000);
}
}
void andar_posA23(){
digitalWrite(dirPin1, HIGH);
digitalWrite(dirPin2, HIGH);
// Spin motor slowly
for(int x = 0; x < stepsPerRevolution; x++)
{
digitalWrite(stepPin1, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin1, LOW);
delayMicroseconds(2000);
digitalWrite(stepPin2, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin2, LOW);
delayMicroseconds(2000);
}
servo2.write(0); // move the servo to 0 degrees
delay(1000); // wait for 1 second
servo1.write(90); // move the servo to 90 degrees
delay(1000); // wait for 1 second
servo1.write(180); // move the servo to 180 degrees
delay(1000); // wait for 1 second
for(int x = 0; x < stepsPerRevolution; x++)
{
digitalWrite(stepPin1, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin1, LOW);
delayMicroseconds(2000);
digitalWrite(stepPin2, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin2, LOW);
delayMicroseconds(2000);
}
}
void andar_posB45(){
digitalWrite(dirPin1, HIGH);
digitalWrite(dirPin2, HIGH);
// Spin motor slowly
for(int x = 0; x < stepsPerRevolution; x++)
{
digitalWrite(stepPin1, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin1, LOW);
delayMicroseconds(2000);
digitalWrite(stepPin2, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin2, LOW);
delayMicroseconds(2000);
servo3.write(0); // move the servo to 0 degrees
delay(1000); // wait for 1 second
servo1.write(90); // move the servo to 90 degrees
delay(1000); // wait for 1 second
servo1.write(180); // move the servo to 180 degrees
delay(1000); // wait for 1 second
for(int x = 0; x < stepsPerRevolution; x++)
{
digitalWrite(stepPin1, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin1, LOW);
delayMicroseconds(2000);
digitalWrite(stepPin2, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin2, LOW);
delayMicroseconds(2000);
}
}
}
void andar_posB56(){
digitalWrite(dirPin1, HIGH);
digitalWrite(dirPin2, HIGH);
// Spin motor slowly
for(int x = 0; x < stepsPerRevolution; x++)
{
digitalWrite(stepPin1, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin1, LOW);
delayMicroseconds(2000);
digitalWrite(stepPin2, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin2, LOW);
delayMicroseconds(2000);
servo4.write(0); // move the servo to 0 degrees
delay(1000); // wait for 1 second
servo1.write(90); // move the servo to 90 degrees
delay(1000); // wait for 1 second
servo1.write(180); // move the servo to 180 degrees
delay(1000); // wait for 1 second
for(int x = 0; x < stepsPerRevolution; x++)
{
digitalWrite(stepPin1, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin1, LOW);
delayMicroseconds(2000);
digitalWrite(stepPin2, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin2, LOW);
delayMicroseconds(2000);
}
}
}
void andar_posC78(){
digitalWrite(dirPin1, HIGH);
digitalWrite(dirPin2, HIGH);
// Spin motor slowly
for(int x = 0; x < stepsPerRevolution; x++)
{
digitalWrite(stepPin1, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin1, LOW);
delayMicroseconds(2000);
digitalWrite(stepPin2, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin2, LOW);
delayMicroseconds(2000);
}
servo5.write(0); // move the servo to 0 degrees
delay(1000); // wait for 1 second
servo1.write(90); // move the servo to 90 degrees
delay(1000); // wait for 1 second
servo1.write(180); // move the servo to 180 degrees
delay(1000); // wait for 1 second
for(int x = 0; x < stepsPerRevolution; x++)
{
digitalWrite(stepPin1, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin1, LOW);
delayMicroseconds(2000);
digitalWrite(stepPin2, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin2, LOW);
delayMicroseconds(2000);
}
}
void andar_posC89(){
digitalWrite(dirPin1, HIGH);
digitalWrite(dirPin2, HIGH);
// Spin motor slowly
for(int x = 0; x < stepsPerRevolution; x++)
{
digitalWrite(stepPin1, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin1, LOW);
delayMicroseconds(2000);
digitalWrite(stepPin2, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin2, LOW);
delayMicroseconds(2000);
}
servo6.write(0); // move the servo to 0 degrees
delay(1000); // wait for 1 second
servo1.write(90); // move the servo to 90 degrees
delay(1000); // wait for 1 second
servo1.write(180); // move the servo to 180 degrees
delay(1000); // wait for 1 second
for(int x = 0; x < stepsPerRevolution; x++)
{
digitalWrite(stepPin1, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin1, LOW);
delayMicroseconds(2000);
digitalWrite(stepPin2, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin2, LOW);
delayMicroseconds(2000);
}
}