Button Help, Up, Down, Select


i trying create timer aeroponic system. menu display choices.
1. off time (which amount of time in minutes timer off.
2. on time  (which amount of time in minutes timer on.
the timer "on time" activate solid state relay , keep power on pump amount of time selected.

i pulled code off internet , guidance.
digital pins 5 , 6 attached tactile switches, increment on time variable.
i have added 3rd tactile switch on digital pin 3, "select button" let me choose whether working "time off" or "time on"
right following code working , displays "time on myvar.
i hope makes sense, if not attempt provide more information.
thanks, john

code: [select]

#include <liquidcrystal.h>

liquidcrystal lcd(7,8,9,10,11,12);

//set buttons pin numbers
byte incrementbutton = 5;
byte decrementbutton = 6;
byte selectbutton = 3;

//global variables
int incrementstate = 0; //variable read increment button (either high or low)
int decrementstate = 0; //variable read decrement button (either high or low)
int counter = 0; //variable store count
int lastincrementstate = 0;
int lastdecrementstate = 0;

void setup()
{
   pinmode(incrementbutton, input); //set incrementbutton input
   pinmode(decrementbutton, input); //set decrementbutton input
   lcd.begin(16, 2); //set lcd's number of columns , rows:
   lcd.print("time on"); //print message on lcd "time on"
   lcd.setcursor(0,2); //set cursor @ row 2 print next line
   lcd.print("time off"); ////print message on lcd "time off"
}//end of setup

void loop()
{
   lcd.setcursor(12, 0);
   incrementstate = digitalread(incrementbutton); //read increment button state
   decrementstate = digitalread(decrementbutton); //read decrement button state
   if(incrementstate != lastincrementstate) //compare increment button state last state
   {
      if(incrementstate == low)//increment button pressed
      {
         counter = counter + 1; //increment counter
         lcd.print(counter); //print on serial monitor
         lcd.print("   "); //3 blank spaces
         delay(20); //debounce delay
      }
   }
   lastincrementstate = incrementstate;

   if(decrementstate != lastdecrementstate)//compare decrement state laststate
   {
      if(decrementstate == low)//decrement button pressed
      {
         counter = counter - 1; //decrement counter
         lcd.print(counter); //print on serial monitor
         lcd.print("   "); //3 blank spaces
         delay(20); //debounce delay
      }
   }
   lastdecrementstate = decrementstate;
}//end of loop

so want third button toggle between 2 states? ok, use latch.

code: [select]
static boolean select = digitalread(3);
if(select !=  lastselectstate) // lastselectstate need declaired boolean @ top of code.
{
   if(select == high)
   {
     lastselectstate = select; // notice put in here , not outside if statement.
     state = !state; // declare boolean @ top of code. set false
   }
}

if(state == high)
{
  // code time on
}
else
{
  //time off
}



Arduino Forum > Using Arduino > Project Guidance > Button Help, Up, Down, Select


arduino

Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support