error: expected unqualified-id before '{' token

Hi, I'm new to all this and was trying to make a button add to a counter and also print a single name out on the first press. I had this code, and received the error on line 36 (if (val == HIGH) {

#include <LiquidCrystal.h>

int button = 8;
int val;
int count = 0;
int press;
int Y;
const int rs = 12,
en = 11,
d4 = 5,
d5 = 4,
d6 = 3,
d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
lcd.begin(16, 2);
pinMode(button, INPUT);
}

void loop() {
val = digitalRead(button);
if (val == HIGH) {
press = count++;
Y = 1 * press + 0; //y=mx+b
delay(250);
}
lcd.setCursor(0, 0);
lcd.print("Hi, my name");
lcd.setCursor(15, 1);
lcd.print(Y);
}

{
val = digitalRead(button);
if (val == HIGH) {
lcd.setCursor(0, 1);
lcd.print("is Joe");
}

{
  val = digitalRead(button);
  if (val == HIGH) {
    lcd.setCursor(0, 1);
    lcd.print("is Joe");
  }

Is not in a function.

Please remember to use code tags when posting code

Hello zzzzwwwwdddd99,

I found this site very helpful when I was learning C C Tutorial

I suggest you pay particular attention to this part C - Functions

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.