I have issue with the if statement were "funkar" doesnt work properly, by that i mean it pops up barely a second. Why?
void loop() {
buttonState = digitalRead(8);
lcd.setCursor(1, 17);
digitalWrite(13, HIGH);
delay(5000);
digitalWrite(13, LOW);
delay(5000);
if (buttonState == HIGH);{
Serial.println("Funkar");
lcd.clear();
lcd.print("Funkar");
if (buttonState == LOW);{
Serial.println("Noll");
lcd.clear();
lcd.print("Noll");
delay(1000);}
}
That's an entire if statement…
and so is this
if (buttonState == LOW);
HTH
a7
Welcome to the forum
if (buttonState == HIGH);{
Delete the semicolon after the if
It is the only code that depends on the test being true and the code in the subsequent block will be executed unconditionally
In addition, you are reading buttonState at the beginning of the loop(). You then have delays of 10 sec.
You will not get a response to your button press for 10 sec. Unless that is what you want.
Consider the principle of exclusion. If something is true, it can't be false. If something is false, it can't be true. A thing can not be both true and false at the same time.
if (buttonState == HIGH){
...
}
else{ // if it's not HIGH, it must be LOW
...
}
Hello, thank you for taking time and making me figure it out.
Ive made some slightly changes based on what I've understand, but it still seem to be unchanged.
buttonState = digitalRead(8);
lcd.setCursor(1, 17);
digitalWrite(13, HIGH);
delay(3000);
digitalWrite(13, LOW);
delay(3000);
if (buttonState == HIGH){
Serial.println("Funkar");
lcd.clear();
lcd.print("Funkar");}
else{
Serial.println("Noll");
lcd.clear();
lcd.print("Noll");
}
}
Please post a complete, compilable sketch.
Of course!
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int buttonState = 0;
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
Serial.begin(9600);
pinMode(13,OUTPUT);
pinMode(8, INPUT);
}
void loop() {
buttonState = digitalRead(8);
lcd.setCursor(1, 17);
digitalWrite(13, HIGH);
delay(3000);
digitalWrite(13, LOW);
delay(3000);
if (buttonState == HIGH){
Serial.println("Funkar");
lcd.clear();
lcd.print("Funkar");}
else{
Serial.println("Noll");
lcd.clear();
lcd.print("Noll");
}
}
Please describe how the program should behave, and how the actual behaviour differs from that.
You would have to press the button at EXACTLY the correct time to detect a button press because you have 6 seconds of delays. I bet if you hold the button down for 6 or more seconds it will work as you expect. delay() calls are bad for most applications.
2 Likes
Also, how is your button switch wired?
Well, im trying to change the lcd based on whenever pin8 detects a signal/pulse. Which is now currently getting a pulse signal from output pin (13).
Well, its just a pulse from pin13 as output directly to pin8 as input.
What are you really doing? You call it 'buttonState' but now you talk about receiving pulses?
???
Doesn't make sense to me. If, in fact, pin 8 is connected to pin 13 then pin 8 will ALWAYS read LOW the way you have it coded. Remember this code executes sequentially.
1 Like
What is your goal? What is the final desired result? Surely not a thing that prints, "Funkar, Noll, Funcar, Noll" for ever and ever?
I was trying to change the lcddisplay with the help of output 13. now i realised that the input 8 is only working when i send a "signal" through a pushbutton(which i did not have) which i thought would be accomplished with an output(13) like a pulse. Im sorry if I'm not making any sense, I'm super new to this. But now it works, i removed pin 13 as a "button" and replaced it with a real pushbutton. it works! Thank you for your time !
Best regards
If you have an Arduino, you always have a test "button". Configure some input as INPUT_PULLUP option, and then use a jumper wire connected to ground on one end, to touch the input pin. It will register a "button press" each time you touch.
1 Like
It us usually safer to connect one end of the jumper to the pin and then touch the other end to GND because large GND areas such as the outer case of the USB connector are easier to use and less prone to mistakes than trying to touch a pin