Hi .. i'm a newb
i tried this code ... on my arduino (gift) and it seems to go beyond the "OFF" & "MAX"
how do i make it count from OFF to 5(MAX) ... because this code its prints OFF and MAX on display .. but he goes beyond that with -1 -2 -3 -4 -5 ..and when i press my +button ... i have to go from -2 or how many times i pushed the botton after OFF
and for MAX the same ..goes after my if (buttonPushCounter >= 5)
AND i want to modify this code to control a blinking led ...
something like :
if OFF = closed led
if 1 = 1/min
if 2 = 2/min
if 3 = 3/min
if MAX= 4/min
- to display this
PS i don't have any coding knowledge sry
but im triend to learn but i got this 2 days ago ..i i dont want to trow it away because i dont know how this is done
I have browsed the forum for something similar ..cant find anything ...
Aaron_dyer:
Thanks to both of you....I used both of the information given...my code now is shown below...Its working...I just have to tweak it a little with some delays etc...
#include <LiquidCrystal.h>
LiquidCrystal lcd(7,8,9,10,11,12);
const int buttonPin = 5; // the pin that the Up pushbutton is attached to
const int buttonPin1 = 6; // the pin that the Down pushbutton is attached to
// Variables will change:
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState5 = 0; // current state of the button
int buttonState6 = 0; // current state of the button
int lastButtonState = 0; // previous state of the buttonvoid setup() {
// initialize the button pin as a input:
pinMode(buttonPin, INPUT);
pinMode(buttonPin1, INPUT);
lcd.begin(16,2);
lcd.setCursor(0,1);
lcd.print("Volume:");
}
void loop() {
// read the pushbutton up input pin:
buttonState5 = digitalRead(buttonPin);
// compare the buttonState to its previous state
if (buttonState5 != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState5 == HIGH)
{
buttonPushCounter++;
lcd.setCursor(7,1);lcd.print(buttonPushCounter);
}delay(50);
}
// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState5;// read the pushbutton down input pin:
buttonState6 = digitalRead(buttonPin1);
// compare the buttonState to its previous state
if (buttonState6 != lastButtonState) {
// if the state has changed, decrement the counter
if (buttonState6 == HIGH)
{
buttonPushCounter-=1;
lcd.setCursor(7,1);lcd.print(buttonPushCounter);
}delay(50);
if (buttonPushCounter < 10)
{
lcd.setCursor(8,1);lcd.print(" ");
}if (buttonPushCounter <= 0)
{
lcd.setCursor(7,1);
lcd.print("OFF");
}
if (buttonPushCounter >= 25)
{
lcd.setCursor(7,1);
lcd.print("Max");
}
}
// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState6;
}