i have 3 button i made 2 switch up and down to control on motor i want to control them by last button to turn off their function when i pushed it high , make them turn actuator up and down and all this showed on LCD ?
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // select the pins used on the LCD panel
// define some values used by the panel and buttons
int lcd_key = 0;
int adc_key_in = 0;
int a = 11;
int b = 12;
int c = 13;
int d = A4;
int val = 0;
int counter = 0;
int currentState = 0;
int previousState = 0;
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
#define Bck 10
int read_LCD_buttons(){ // read the buttons
adc_key_in = analogRead(0); // read the value from the sensor
// my buttons when read are centered at these valies: 0, 144, 329, 504, 741
// we add approx 50 to those values and check to see if we are close
// We make this the 1st option for speed reasons since it will be the most likely result
if (adc_key_in > 1000) return btnNONE;
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 195) return btnUP;
if (adc_key_in < 380) return btnDOWN;
if (adc_key_in < 555) return btnLEFT;
if (adc_key_in < 790) return btnSELECT;
return btnNONE; // when all others fail, return this.
}
int voltPin=A5;
//////////////////////////////////////////////////////////////////
// it's a 16x2 LCD so...
int screenWidth = 16;
int screenHeight = 2;
// the two lines
// line1 = scrolling
String line1 = "Easy Life Company - 01001004863";
String line2 = " Whizzzkid Inc. ";
// just some reference flags
int stringStart, stringStop = 0;
int scrollCursor = screenWidth;
//////////////////////////////////////////////////////////////////
void setup()
{
Serial.begin(9600);
pinMode(Bck,OUTPUT);
pinMode(a,OUTPUT); //13
pinMode(b,OUTPUT);//12
pinMode(c,OUTPUT);
pinMode(d,OUTPUT);
pinMode(btnRIGHT,INPUT);
lcd.begin(16, 2); // start the library
lcd.setCursor(0,0); // set the LCD cursor position
analogWrite(Bck,255);
}
void loop()
{
lcd_key = read_LCD_buttons(); // read th
if (lcd_key == btnDOWN && lcd_key == btnUP&& lcd_key == btnRIGHT )
{ lcd.setCursor(0,1);
lcd.print("Eror "); // push button "DOWN" and show the word on the screen
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
}
else if (lcd_key == btnUP)
{
lcd.setCursor(0,1);
lcd.print("Up Stairs "); // push button "UP" and show the word on the screen
digitalWrite(a,HIGH);
digitalWrite(b,LOW);
}
else if (lcd_key == btnDOWN)
{
lcd.setCursor(0,1);
lcd.print("Down Stairs "); // push button "DOWN" and show the word on the screen
digitalWrite(a,LOW);
digitalWrite(b,HIGH);
}
else if (lcd_key == btnRIGHT){
lcd.setCursor(0,1);
lcd.print("actuator mode "); // push button "UP" and show the word on the screen
currentState = 1;
}
else if (lcd_key == btnUP)
{
lcd.setCursor(0,1);
lcd.print("actuator up "); // push button "DOWN" and show the word on the screen
digitalWrite(c,LOW);
digitalWrite(d,HIGH);
}
else if (lcd_key == btnDOWN)
{
lcd.setCursor(0,1);
lcd.print("actuator down "); // push button "DOWN" and show the word on the screen
digitalWrite(c,LOW);
digitalWrite(d,HIGH);
}
else if (lcd_key ==btnNONE )
{
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
/////////////////////////////////////////////////////////////////
lcd.setCursor(scrollCursor, 1);
lcd.print(line1.substring(stringStart,stringStop));
delay(300);
lcd.clear();
if(stringStart == 0 && scrollCursor > 0){
scrollCursor--;
stringStop++;
} else if (stringStart == stringStop){
stringStart = stringStop = 0;
scrollCursor = screenWidth;
} else if (stringStop == line1.length() && scrollCursor == 0) {
stringStart++;
} else {
stringStart++;
stringStop++;
}
/////////////////////////////////////////////////////////
// lcd.setCursor(0,1);
lcd.print("Break! ");
//lcd.print();
/////////////////
float val = analogRead(voltPin);
float VoltRead= map(val, 346, 679, 18.4, 37);
//lcd.print(VoltRead);
//lcd.print(" ");
//lcd.print(val);
/////////////////////////////////// //TESTING PATTERNS
//////////////////////////////////////////////////////////////////////////////
if(VoltRead<23) /////Less than 23
{
lcd.setCursor(0,0);
lcd.print("Battery:");
lcd.setCursor(9,0);
lcd.print("20%");}
}