Hi! i have a problem: i have this menu system, witch is controlled with a 4x4 keypad and a 16*2 LCD screen. The third Switch case (in the row) is not activated, by that i mean, the loop returns itself to the top, and restarts. What could be the solution? I tried to write it using if closes, but the result was the same. Thanks!
maybe it is easier like this:
the code:
#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
const byte numRows= 4;
const byte numCols= 4;
char keymap[numRows][numCols]=
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[numRows] = {13,12,11,10};
byte colPins[numCols]= {9,8,7,6};
Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);
int stepPin = 2;
int dirPin = 3;
int buttonPin = 4;
void setup()
{
Serial.begin(9600);
lcd.begin(16, 2);
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
pinMode(buttonPin,INPUT);
lcd.setCursor(0,0);
lcd.print("DIY Video Slider");
lcd.setCursor(5,1);
lcd.print("V 1.0");
delay(5000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("BY:");
lcd.setCursor(3,1);
lcd.print("Jancsik Gergo");
delay(5000);
lcd.clear();
}
void loop()
{
lcd.setCursor(0,0);
lcd.print("Left-Right A");
lcd.setCursor(0,1);
lcd.print("Right-Left B");
char Direction;
do
{
Direction = myKeypad.getKey();
} while (Direction == NO_KEY);
switch (Direction)
{
case 'A':
digitalWrite(dirPin, LOW);
break;
case 'B':
digitalWrite(dirPin, HIGH);
break;
}
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Video Mode A");
lcd.setCursor(0,1);
lcd.print("Time Lapse B");
char Mode;
do
{
Mode = myKeypad.getKey();
} while (Mode == NO_KEY);
switch (Mode)
{
case 'A':
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" Select Speed ");
lcd.setCursor(0,1);
lcd.print(" 1 2 3 ");
int Speed;
do
{
Speed = myKeypad.getKey()-48;
} while (Speed == NO_KEY);
switch (Speed)
{
case 1:
Move(6000);
break;
case 2:
Move(3000);
break;
case 3:
Move(1000);
break;
}
}
case 'B':
break;
}
}
void Move(int Speed)
{
for(int Step=0;Step<=2500;Step++)
{
if(Step<400)
Speed=1500;
digitalWrite(stepPin, HIGH);
delayMicroseconds(Speed);
digitalWrite(stepPin, LOW);
delayMicroseconds(Speed);
}
}
V.1.2.ino (2.53 KB)