Expected initializer missing for counter

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:

  1. I'm not sure if I'm declaring the "count" variable in the correct way
  2. 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)" );
  }
}

Undoubtedly miss matched "{}". The IDE editor will show you problem if you let it.

Paul

Bluenick2100:
Thanks in advance for any info

    if (Serial.available()) {

// wait a bit for the entire message to arrive
   delay(100);

Look into proper asynchronous Serial communication....

int countWhat must every declaration end with ?

Hi

First place to look is the line where you declare "count"

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int buttonPin = 8;
int count

void setup(){

Your missing a semi-colon at the end of the line hence the error message.

It should read

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int buttonPin = 8;
int count;

void setup(){

Also you are going wrong with your LCD display

{
  // 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)" );
  }

First of all your comment correctly notes that the second line is index 1 but you set the cursor to position 0, 2.

Secondly your lcd.print statement will print the string "Count is (count)" on the display.

What you actually need is

   lcd.print("Count is ");
   lcd.print(count);

Which will print the value contained in count after the string "Count is ".

Ian

Thanks! I don't know what the hell I'm thinking, I think I need to stand up and take a break