Loading...
Pages: [1]   Go Down
Author Topic: Problems of programming  (Read 233 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i'm try to make a quiz for my project however im encountering a problem when the user have to chose the answer as the previous output is being outputted. the above is my code


void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):

  // print the number of seconds since reset:
    buttonState = digitalRead(buttonPin);
    lcd.setCursor(1, 7);
  for(i=0;i<1;i++){
  if (buttonState == HIGH) {     
    // turn LED on:
   
    lcd.print("SPORTS WAS CHOSEN");
    delay(1000);
    lcd.clear();
    lcd.setCursor(0, 0);
    buttonState == LOW;
  }
  } 
    lcd.print("Which team won ");
    lcd.setCursor(0, 1);
    lcd.print("the World cup?");
    lcd.setCursor(0, 2);
    lcd.print(" a. A");
    lcd.setCursor(0, 3);
    lcd.print(" B. B");
    buttonState = digitalRead(buttonPin);
    if(buttonState == HIGH){
     
         lcd.print(" Wrong answer ");
         digitalWrite(led, HIGH);
         delay(1000);
    }
  }
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 248
Posts: 16535
Available for Design & Build services
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Try a single = here:

    lcd.print("SPORTS WAS CHOSEN");
    delay(1000);
    lcd.clear();
    lcd.setCursor(0, 0);
    buttonState == LOW;   <<<
  }
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

first of all thanks for your help smiley

i try that but the problem is that when i'm pushing the swicth again the bulb is going on and also the text "sport was chosen"
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 248
Posts: 16535
Available for Design & Build services
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

okay, you are probably seeing "button bounce"

Go check the Learning section for "debounce" so the button is only read once when pressed.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 314
Posts: 35518
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  for(i=0;i<1;i++){
Please explain that.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

it basically  loops for 1 time i did to experiment.  however it does noting 
Logged

Pages: [1]   Go Up
Print
 
Jump to: