Anyone can teach me about how to use keypad to adjust arduino code(uploaded).
My project(vending machine) has 6 slot for product with different prices.
i wish to use the keypad to change the prices without using arduino IDE.
EXAMPLE, my 1st product is RM0.10 and i want to change it to RM0.50 using keypad.
#include<Servo.h>
#include <Keypad.h>
volatile float coinsValue = 0.00;
const int coinInt = 1;
const byte ROWS = 3;
const byte COLS = 3;
Servo myservo1;
Servo myservo2;
int posi = 0;
int pos = 0;//analog servo speed
int door = 0;//for dc gear motor
float array [6] = {0.00, 0.00, 0.00, 0.00, 0.00, 0.00};//use for multi-select or repeat select to purchase item(maximum 6 items in one purchase)
float Value1 = 0.00;
float Value2 = 0.00;
float Value3 = 0.00;
float Value4 = 0.00;
float Value5 = 0.00;
float Value6 = 0.00;
int motor1 = 0;
int motor2 = 0;
float total = 0.00;
boolean entered = false;
char keys [ROWS] [COLS] = {
{'1', '2', '3',},
{'4', '5', '6',},
{'*', '0', '#',}
};
byte rowPins[] = { 13, 12, 11 };
byte colPins[] = { 10, 9, 8 };
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup()
{ pinMode(7, OUTPUT);
pinMode(6,OUTPUT);
Serial.begin(9600);
attachInterrupt(coinInt, coinInserted, RISING);
myservo1.attach(4);
myservo2.attach(5) ;
myservo1.write(pos);
myservo2.write(pos);
}
void coinInserted()
//The function that is called every time it receives a pulse
{
coinsValue = coinsValue + 0.10;
//1 pulse=RM0.10,2 pulse= RM0.20, 5 pulse=RM0.50(this is my country coins)
Serial.println("Your already pay RM ");
Serial.print(coinsValue);
}
void loop()
{
char key = kpd.getKey();
if (key) // Check for a valid key.
if (key == '1') {
if (posi < 6) {
array[posi] = 0.10;//price for product
posi = posi + 1;
Serial.println("Value 1: ");
Serial.println(key);
Serial.println("");
}
motor1 = motor1 + 1;//will keep add 1 to motor1 if keep press key "1"(maximum 6 times)
}
if (key == '2') {
if (posi < 6) {
array[posi] = 0.20;
posi = posi + 1;
Serial.println("Value 2: ");
Serial.println(key);
Serial.println("");
}
motor2 = motor2 + 1;
}
if (key == '3') {
if (posi < 6) {
array[posi] = 0.30;
posi = posi + 1;
Serial.println("Value 3: ");
Serial.println(key);
Serial.println("");
}
}
if (key == '4') {
if (posi < 6) {
array[posi] = 0.40;
posi = posi + 1;
Serial.println("Value 4: ");
Serial.println(key);
Serial.println("");
}
}
if (key == '5') {
if (posi < 6) {
array[posi] = 0.50;
posi = posi + 1;
Serial.println("Value 5: ");
Serial.println(key);
Serial.println("");
}
}
if (key == '6') {
if (posi < 6) {
array[posi] = 0.60;
posi = posi + 1;
Serial.println("Value 6: ");
Serial.println(key);
Serial.println("");
}
}//maximum 6 times to multi-select or repeat select with keypad "1" to "6"
if (key == '#') {
Value1 = array[0];
Value2 = array[1];
Value3 = array[2];
Value4 = array[3];
Value5 = array[4];
Value6 = array[5];
Serial.println("Total:");
total = Value1 + Value2 + Value3 + Value4 + Value5 + Value6 ;
Serial.println("You have to pay amount RM ");
Serial.println(total);
entered = true;
}//use the "#" as enter and show the total value need to pay
if (coinsValue >= total && entered == true) {//put the coin to coin acceptor until value equal or over the total
Serial.println("OKAY");
delay(2000);
if (motor1 != 0) {//when the motor1 not equal 1
for (int x = 0; x < motor1; x++) {//if motor1=2 it will function 2 times
pos = 5;
myservo1.write(pos);
delay(3000);
pos = 0;
myservo1.write(pos);
delay(3000);
Serial.println("ggwp");
}
motor1 = 0;//reset the motor1
}
if (motor2 != 0) {
for (int x = 0; x < motor2; x++) {
pos = 5;
myservo2.write(pos);
delay(3000);
pos = 0;
myservo2.write(pos);
delay(3000);
Serial.println("ggwp1");
}
motor2 = 0;
}
if (motor3 != 0) {
for (int x = 0; x < motor3; x++) {
pos = 5;
myservo3.write(pos);
delay(3000);
pos = 0;
myservo3.write(pos);
delay(3000);
Serial.println("ggwp1");
}
motor3 = 0;
}
if (motor4!= 0) {
for (int x = 0; x < motor4; x++) {
pos = 5;
myservo4.write(pos);
delay(3000);
pos = 0;
myservo4.write(pos);
delay(3000);
Serial.println("ggwp1");
}
motor4 = 0;
}
if (motor5 != 0) {
for (int x = 0; x < motor5; x++) {
pos = 5;
myservo5.write(pos);
delay(3000);
pos = 0;
myservo5.write(pos);
delay(3000);
Serial.println("ggwp1");
}
motor5 = 0;
}
if (motor6 != 0) {
for (int x = 0; x < motor6; x++) {
pos = 5;
myservo6.write(pos);
delay(3000);
pos = 0;
myservo6.write(pos);
delay(3000);
Serial.println("ggwp1");
}
motor6 = 0;
}
door = 1;//for starting dc gear motor (automatic door)
if(motor1==0 && motor2==0 && motor3==0 && motor4==0 && motor5==0 && motor6==0 && door==1){
digitalWrite(7,HIGH);//dc gear motor forward
analogWrite(6,5);//speed control
delay(4000);
digitalWrite(6,LOW);//dc gear motor stop
Serial.println("qqq");
}//it will start function after all product is drop from the slots
posi = 0;//reset the value and waiting the next purchase
Value1 = 0.00;//reset the value and waiting the next purchase
Value2 = 0.00;//reset the value and waiting the next purchase
Value3 = 0.00;//reset the value and waiting the next purchase
Value4 = 0.00;//reset the value and waiting the next purchase
Value5 = 0.00;//reset the value and waiting the next purchase
Value6 = 0.00;//reset the value and waiting the next purchase
total = 0.00;//reset the value and waiting the next purchase
coinsValue = 0.00;//reset the value and waiting the next purchase
for (int x = 0; x < 3; x++) {
array[x] = 0;
}
entered = false;
}
}
Here is my component list:
1.analog servo motor x6(as3103)
2.dc gear motorx1
3.keypad 3x4
4.coin acceptor(can accept 6 difference types)50sen=5 pulse,20sen =2 pulse,10sen =1 pulse
5.LCD displays 1602
Here is my vending machine(selling components) function:
1.Need to choose the product 1st(multi-select or repeat select)(maximum 6 times)
2.Press the “#” and it will show total cost
3.Put coin into coin acceptor until same value or over and it will show how much you pay
4.It will show “OKAY” and delay 2 sec servo motor will start function 1by1
5.Servo motor finish function, it will trigger dc gear motor open the door
6.Delay about 20sec, it will auto turn off the door
I wish to add the function “using keypad to change product value”