Hi everyone, I'm just practicing making a counter that increments a count by one each time a button is pressed, then have that count displayed on 16x2 lcd screen. I'm having a few small problems so far and I expect a few more in the future. Here is where I'm currently at:
- I'm not sure if I'm declaring the "count" variable in the correct way
- When I try to validate the code I keep getting the error "expected initializer before 'void'"
For some reason I can see my mistake. Any help would be greatly appreciated!
That's the first set of problems, after I get this cleared up I'm going to attempt to use a keypad to set the amount of times the button can be pressed before an LED lights up. I'm guessing it's gonna be a challenge to write the correct code for that.
Thanks in advance for any info
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int buttonPin = 8;
int count
void setup(){
//set button as input
pinMode(buttonPin,INPUT);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// initialize the serial communications:
Serial.begin(9600);
}
void loop()
{
// when characters arrive over the serial port...
if (Serial.available()) {
// wait a bit for the entire message to arrive
delay(100);
// clear the screen
lcd.clear();
// read all the available characters
while (Serial.available() > 0) {
// display each character to the LCD
lcd.write(Serial.read());
}
}
{
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 2);
//when button is pressed increment the count
if(buttonPin = HIGH, count++);
// print the number of times the button is pressed:
lcd.print("Count is (count)" );
}
}