i need help about arduino code for combine LCD,COIN ACCEPTOR, CONTINUOUS ROTATION SERVO & KEYPAD to build a vending machine~~
my vending machine function is:
1.choose the product with keypad(can choose multi-product in one times)
2."*"use as cancel the order and “#” use as confirm order
3.LCD will display the total cost of product
4.insert coin to coin acceptor untill reach the total cost
5.after reach the total cost,servo will start function 1 by 1
my component list
1.LCD 1602C
2.SERVO AS3103
3.KEYPAD 3X4
4.COIN ACCEPTOR 6types
#include <Keypad.h>
#include<Servo.h>
Servo myservo;
int pos = 0;
const byte ROWS = 4;
const byte COLS = 3;
char keys [ROWS] [COLS] = {
{'1', '2', '3',},
{'4', '5', '6',},
{'7', '8', '9',},
{'*', '0', '#',}
};
byte rowPins[] = { 9, 8, 7, 6 };
byte colPins[] = { 12, 11, 10 };
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
#define ledpin 13
void setup()
{
myservo.attach(2);
myservo.write(pos);
Serial.begin(9600);
}
void loop()
{
char key = kpd.getKey();
if (key) // Check for a valid key.
{
switch (key)
{
case '1':
Serial.println(key);
pos = 0;
myservo.write(pos);
break;
case '2':
Serial.println(key);
pos = 5;
myservo.write(pos);
delay(1375);
pos = 0;
myservo.write(pos);
break;
case '3':
Serial.println(key);
break;
case '4':
Serial.println(key);
break;
case '5':
Serial.println(key);
break;
case '6':
Serial.println(key);
break;
case '7':
Serial.println(key);
break;
case '8':
Serial.println(key);
break;
case '9':
Serial.println(key);
break;
case '0':
Serial.println(key);
break;
case '*':
Serial.println(key);
break;
case '#':
Serial.println(key);
break;
}
}
}
i only know use the case “1” start the servo and case"2" stop the servo
i dont know where to start to write the 1st function, pls give me some suggestion
ty for helping~~~