Calling Funtions not working

I did somthing stupid or its just I dont know what Im doing... All I need is when "button 1 - 4" is pressed it should display in the serial and on my lcd. I wanted to use funtions because its cleaner and I am writing non blocking code after for the first time and I know its going to be complicated. I already tested everything (button and lcd WORKING)

button has a pull down resistor

#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);


#define button1 6
int bV1;
#define button2 7
int bV2;
#define button3 8
int bV3;
#define button4 9
int bV4;


void setup() {
      lcd.begin(16, 2);
  Serial.begin(9600);
pinMode(button1, INPUT);
pinMode(button2, INPUT);
pinMode(button3, INPUT);
pinMode(button4, INPUT);
}

void loop() {

bV1 = digitalRead(button1);
bV2 = digitalRead(button2);
bV3 = digitalRead(button3);
bV4 = digitalRead(button4);
    buttonPressed;
}

void buttonPressed(){

lcd.write("BUTTONPRESSED FUNTION");
Serial.print("BUTTONPRESSED FUNTION");

  if(bV1 == 1){
  Serial.println("BUTTON 1 PRESSED");
    lcd.setCursor(0,0);

    lcd.print("BUTTON 1 PRESSED");
  }
  else if(bV2 == 1){
      Serial.println("BUTTON 2 PRESSED");
          lcd.setCursor(0,1);
        lcd.print("BUTTON 2 PRESSED");
    }
    else if(bV3 == 1){
          lcd.setCursor(0,0);
      Serial.println("BUTTON 3 PRESSED");
        lcd.print("BUTTON 3 PRESSED");
   }
    else if(bV4 == 1){
          lcd.setCursor(0,1);
      Serial.println("BUTTON 4 PRESSED");
        lcd.print("BUTTON 4 PRESSED");
    }

}

I dont know how to use a funtion properly sorry :sweat_smile:
also I did some messing arround thats why the code is so messy and out of place
Thanks for reading!!!

Edit: fixed up some code so its less messy

When you call a function you need ( )

buttonPressed( );

I told you it was a stupid mistake :rofl:

thanks soo much!!!

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