Pages: [1]   Go Down
Author Topic: How to program buttons for 1602 lcd1602 keypad shield  (Read 1130 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dear all,
because my poor knowledgment I need some help for assign someaction to some buttons for following sketch.
Of course I'll pay for that job.

Actual Hardware:

-Arduino Uno
- LCD Keypad shield 1602 (with 6 butttons)(8, 9, 4, 5, 6, 7)
- Reed switch connected to digital pin 2
- Some wiring
- 10kohm resistance (pullup) to ground

Purpose of my sketch:  pulse counting (rpm) of a wheel with an LCD 1602 display with keypad and connected to an excel spreadsheet.
Actual state: sketch who works perfectly and fulfills my needs ….but

These are my needs:

1)I would like to configure 2 buttons of the keypad for adding/substracting 1 unit on every push of each button

Button UP:  it has to do following calibr = calibr + 0.001;
 On every press the new value must appear on the screen

Button DOWN: calibr = calibr - 0.001;
On every press the new value must appear on the screen

Button LEFT = (store "pulsecounter" value in eeprom). By reconnecting or resetting, the value of "pulsecounter" should restart counting from saved value

2) I would like to calculate the speed  ( rev. por second) every time "pulsecounter" reaches 10,20,30.. ( every 10 pulses) and to show it on display (instead actual Time  mm:ss)

3) I also would like to fade the backlight through the other 2 free buttons or a menu on the lcd shield.

I'll pay ( payment method as you prefere) for every step you can solve.If you think you're able to solve one of my needs, please feel free to contact me here..or better by mail
efervescencio at hotmail dot com.

thanks to all

Code:
/*  Pulse counter with 1602 lcd1602 keypad shield*/

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

const float calibr = 1.673;   // calibration factor
const int  sensor = 2;   

long pulsecounter = 0;   // pulse counter
int actualcounter = 0;         // actual state of counter
int previouscounter= 0;     // previous state of counter
int second = 0;
int minute = 0;
int msg=0;
float meters = 0.00;
long lastEvent = 0;  // time for last pulse
int interval = 30;    // debounce time for ignore double pressing

void setup()
 {
  Serial.begin(19200);
  pinMode(sensor, INPUT);    // initializing sensor as input
  lcd.begin(16, 2); // lcd library starting
  lcd.setCursor(0,0);
  lcd.print("C=");
  lcd.setCursor(2,0);
  lcd.print(calibr,3);
  if(msg==0)       //welcome message show only once
     {
       lcd.setCursor(0,0);
       lcd.print("Counter");
       lcd.setCursor(1,1);
       lcd.print("Reset OK");
       delay(1000);
       msg = 1;
       lcd.clear();
       lcd.setCursor(0,0);
  lcd.print("C=");
  lcd.setCursor(2,0);
  lcd.print(calibr,3);
     }
}

void loop()
 {
 
 
  actualcounter= digitalRead(sensor); // digital read of sensor state
 if (actualcounter != previouscounter) // compares actual state with it previous
    {

 if (actualcounter == HIGH && millis() - lastEvent > interval)
 // ignores a second press if it’s too close to the previous
         {
  lastEvent = millis();  // writes time for last valid pulse/press
    counterr++;
      meters= counter * calibr / 1000 ;
      Serial.println(counter);
              {
  lcd.setCursor(0,1); //  cursor on second line "1" and  0 spaces
  lcd.print("Dis=");
  lcd.setCursor(4,1) ;
  lcd.print(meters,2);
  lcd.setCursor(8,0);
  lcd.print("P=");
  lcd.setCursor(10,0);
  lcd.print(pulsecounter);
  actualcounter = digitalRead(sensor); 
  minute = millis() / 60000 ;
  second = (millis() / 1000 ) - ( minute* 60 ) ;
  lcd.setCursor(11,1); 
      if (minute < 10) lcd.print("0");    // if minutes <10 it writes a "0" before
       lcd.print(minute);                 // without this code it would be: H:M:S  (1:M:S)
       lcd.print(":");
      if (second < 10) lcd.print("0");  // same reason as above
       lcd.print(second);

            }
        }
    } 
  previouscounter = actualcounter;
 // saves the actual state as the previous one through the loop     
}
Logged

Pages: [1]   Go Up
Jump to: