Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years ago.
Use push button for input option
I use serial for input options and run program, I don't want to use a serial. I want to use push button to specify the option
its my program now
lcd.printf("Lama Pengujian:\n1 = 180 Menit\n2 = 300 Menit\n3 = 480 Menit %"); wait(1.0); char a = pc.getc(); if((a == '1') && k==0) { lcd.cls(); jam=180; lcd.printf("Pengujian 180 Menit\n"); wait(1.0); } if((a == '2') && k==0) { lcd.cls(); jam=300; lcd.printf("Pengujian 300 Menit\n"); wait(1.0); } if((a == '3') && k==0) { lcd.cls(); jam=480; lcd.printf("Pengujian 480 Menit\n"); wait(1.0); }
i want make the program will not continue if I haven't pressed the push button. how if I use a push button for input a value and run the program ?
1 Answer
8 years ago.
You are very close. You need to create a loop to read the keypress. Also, do you need the k==0 check ?
Try:
lcd.printf("Lama Pengujian:\n1 = 180 Menit\n2 = 300 Menit\n3 = 480 Menit %"); wait(1.0); while(1) // permanent loop to read the keypress and then act on the value of the keypress { char a = pc.getc(); if((a == '1') && k==0) { lcd.cls(); jam=180; lcd.printf("Pengujian 180 Menit\n"); wait(1.0); } if((a == '2') && k==0) { lcd.cls(); jam=300; lcd.printf("Pengujian 300 Menit\n"); wait(1.0); } if((a == '3') && k==0) { lcd.cls(); jam=480; lcd.printf("Pengujian 480 Menit\n"); wait(1.0); } }