My code runs, but dosent detect my button press

Hello, im using thinker card to make that my lcd says something one a button on the A0 pin is pressed. it runs, says there’s no errors but when i start it up and press it, nothing happens. Here’s the Cod

#include <Adafruit_LiquidCrystal.h>

int Off = 0;

int On = 0;

int Activation = 0;

Adafruit_LiquidCrystal lcd_1(0);

void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
lcd_1.begin(16, 2);
pinMode(A0, INPUT_PULLUP);

Activation = Off;
digitalWrite(LED_BUILTIN, HIGH);
lcd_1.setBacklight(1);
lcd_1.print("WorkPrinter");
lcd_1.setCursor(0, 1);
lcd_1.print("Press Start");
while (!(Activation == Off)) {
if (A0 == LOW) {
Activation = On;
}
if (Activation == On) {
lcd_1.clear();
lcd_1.setCursor(0, 0);
lcd_1.print("Ready to print");
}
}
}
void loop()
{
delay(10); // Delay a little bit to improve simulation performance
}’

this is C++ btw

You need to put your:
while (!(Activation == Off)) {
if (A0 == LOW) {
Activation = On;
}
inside Loop()

Please use code tags when posting code.

The following will never be true. Perhaps you were thinking of comparing the result of digitalRead(A0) with LOW.

i did the digital read and loop but rigth now its saying error: expected primary-expression before ‘while’

Post the revised code, using code tags.

//
#include <Adafruit_LiquidCrystal.h>

int Off = 0;

int On = 0;

int Activation = 0;


Adafruit_LiquidCrystal lcd_1(0);

void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
  lcd_1.begin(16, 2);
  pinMode(A0, INPUT_PULLUP);

  Activation = Off;
  digitalWrite(LED_BUILTIN, HIGH);
  lcd_1.setBacklight(1);
  lcd_1.print("WorkPrinter");
  lcd_1.setCursor(0, 1);
  lcd_1.print("Press Start");
  Loop(while (!(Activation == Off)) {
    if   digitalRead(A0 == LOW)  {
      Activation = On;
    })
      if (Activation == On)  {
      lcd_1.clear();
      lcd_1.setCursor(0, 0); 
      lcd_1.print("Ready to print");
    }
  }
}
void loop()
{
  delay(10); // Delay a little bit to improve simulation performance
} 

Very imaginative, but you are not yet ready to invent new syntax. The function called loop is where you are expected to put actions to be repeated.

Study some of the basic examples that come with Arduino to see how this is done.

ok ,yeah im new, an i did not start very properly

ok i went to my local library (its has a robotics lab) and we fixed some stuff but now i got this code. but it dosent recognize the liquidcrystal library or smt.


// C++ code
//

int Off = 0;

int On = 0;

int Activation = 0;

Adafruit_LiquidCrystal lcd_1(0);

void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
  lcd_1.begin(16, 2);
  pinMode(A0, INPUT_PULLUP);

  Activation = Off;
  digitalWrite(LED_BUILTIN, HIGH);
  lcd_1.setBacklight(1);
  lcd_1.print("WorkPrinter");
  lcd_1.setCursor(0, 1);
  lcd_1.print("Press Start");
  while (!(Activation == Off)) {
    if (digitalRead(A0) == LOW)  {
      Activation = On;
    }
    if (Activation == On)  {
      lcd_1.clear();
      lcd_1.setCursor(0, 0);
      lcd_1.print("Ready to print");
    }
  }
}
void loop()
{
  delay(10); // Delay a little bit to improve simulation performance
}

it says that liquidcrystal does not name a type and lcd is not declared in this scope. idk im really confused. you can put this in the arduino app itself or thinker and if you wanna know what i meant.

You're not there yet, but this will also cause you some grief.

You forgot to include the Adafruit_LiquidCrystal library.

When starting out with a new device like an LCD, first wire it up correctly (follow a tutorial, Adafruit has some of the best), then run one of the library examples to test it.

Once it is working, add code to do what you want.

This got left out in the edit... Here is an example of a LiquidCrystal sketch... Identify the differences in the example and your sketch.

ok ill try it, but we did it and it did not send

last time *

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