Hi I am having a problem in modifying a program to reset a up-counter to zero.
I am using a Uno and a 16x2 Lcd to count a pulse input. When input pulse stops I want to be able to reset the count back to zero by using a push button switch.
The program I am using has 2 switches one for up counting and the other for down counting.
I am only using the up count switch sw1 in the code and I have added count++; to increase the increment the count by 2 each time the sw1 is activated.
I would like to use sw2 as the means to reset
Have tried various methods but no success.
// test for upp
#include <LiquidCrystal.h>
// swtich 1 connected at Pin 8 and other end to GND
// switch 2 connected at Pin 9 and other end to GND
// Refer Circuit
int sw1 = 8; // Connect pin 8 to SW1
int sw2 = 9; // Connect pin 9 to SW2
int count = 0;
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
void setup()
{
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("SHAW COUNTER");
// Declare Switches as INPUT to Arduino
pinMode(sw1, INPUT);
pinMode(sw2, INPUT);
digitalWrite(sw1, HIGH);
digitalWrite(sw2, HIGH);
}
void loop()
{
if (digitalRead(sw1) == LOW) // if SW1 is pressed perform action described in loop
{
count++; // Increment Count by 1
count++; // added this and gives Increment of 2 which is required
lcd.setCursor(0, 1);
lcd.print(count);
delay(400);
}
if (digitalRead(sw2) == LOW) // if SW2 is pressed perform action described in loop
{
count--; // Decrement Count by 1
if (count < 0)
count = 0;
lcd.setCursor(0, 1);
lcd.print(count);
delay(400);
}
}
Any help would be appreciated
Thanks