Go Down

Topic: Problems of programming (Read 464 times) previous topic - next topic

kdun0001

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);
    }
  }

CrossRoads

Try a single = here:

    lcd.print("SPORTS WAS CHOSEN");
    delay(1000);
    lcd.clear();
    lcd.setCursor(0, 0);
    buttonState == LOW;   <<<
  }
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.
Arduino for Teens available at Amazon.com.

kdun0001

first of all thanks for your help :)

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"

CrossRoads

okay, you are probably seeing "button bounce"

Go check the Learning section for "debounce" so the button is only read once when pressed.
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.
Arduino for Teens available at Amazon.com.

PaulS

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

kdun0001

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

Go Up