What should happen:
Each button press,(X 's are buttons), increments the buttonPushCounterOn value or buttonPushCounteroff value up by one, then restarts after 60. The incremented value of seconds On or Seconds Off prints to LCD accordingly. buttonPushCounterOn value is multiplied by 1,000 to give SecondsOn for use elsewhere. buttonPushCounteroff value is multiplied by 10,000 to give MinutesOff for use elsewhere.
It had been working inconsistently in another program so I took it out to improve it. Now I can't get it to compile. " expected unqualified id before string constant".
Here’s what the interface looks like:
_LCD
| |
[u]| **S.ON / **M.Off|[/u]
X X
On Off
Here is the code:
//Button Incrementor
volatile int buttonPin = 0; //Uno 2 // the pin that the ON pushbutton is attached to
volatile int buttonPin1 = 1; //Uno 3 // the pin that the OFF pushbutton is attached to
// Variables will change:
long int buttonPushCounterOn = 0; // counter for the number of button presses
long int buttonPushCounterOff = 0; // counter for the number of button presses
int buttonStateOn5 = 0; // current state of the button
int buttonStateOff6 = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
int lastButtonStateOff = 0; // previous state of the button
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd (7,8,9,10,11,12); //11RS,12E,13D4,14D5,15D6,16D7
void setup(){
pinMode(buttonPin, INPUT);
pinMode(buttonPin1, INPUT);
lcd.begin(16,2); // set up the LCD's number of columns and rows:
lcd.print("www.MISTFITZ.com"); // Print a message to the LCD.
delay(4000);
lcd.clear();
lcd.setCursor(2,1);
lcd.print("-S.ON");
lcd.setCursor(10,1);
lcd.print("-M.OFF");
attachInterrupt(buttonPin, ISR ,RISING);
attachInterrupt(buttonPin1, ISR ,RISING); }
void ISR()
{
// read the pushbutton ON input pin:
buttonStateOn5 = digitalRead(buttonPin);
// compare the buttonState to its previous state
if (buttonStateOn5 != lastButtonState)
// if the state has changed, increment the counter
if (buttonStateOn5 == HIGH)
buttonPushCounterOn+=1;
if(buttonPushCounterOn > 60)buttonPushCounterOn =0; // rollover after 60.
lastButtonState = buttonStateOn5; // save the current state as the last state, for next time through the loop
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print(buttonPushCounterOn,DEC);
// read the pushbutton OFF input pin:
buttonStateOff6 = digitalRead(buttonPin1);
// compare the buttonState to its previous state
if (buttonStateOff6 != lastButtonStateOff)
// if the state has changed, increment the counter
if (buttonStateOff6 == HIGH)
buttonPushCounterOff+=1;
if(buttonPushCounterOff > 60)buttonPushCounterOff =0; // rollover after 60.
lastButtonStateOff = buttonStateOff6; // save the current state as the last state, for next time through the loop
lcd.setCursor(8,1);
lcd.print(" ");
lcd.setCursor(8,1);
lcd.print(buttonPushCounterOff,DEC);
}
void loop(){
// Timing of the Solenoid
delay(buttonPushCounterOn * 1000); // buttonPushCounterOn * 1000 gives us seconds.
delay(buttonPushCounterOff * 10000); } // buttonPushCounterOff * 1000 gives us seconds.
}