Go Down

Topic: How to escape while control structure with implement of switch case (Read 1 time) previous topic - next topic

CrossRoads

These comments are not correct:

break; // supposed that break the case 1 if other case is being pressed

break; just tells the code to go the the closing } of  the section.  It does not stop anything.

If you want to stop ongoing code, you need to create an Interrupt when a key is pressed, and use that interrupt to stop the ongoing code.
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.

mr_hacker90


These comments are not correct:

break; // supposed that break the case 1 if other case is being pressed

break; just tells the code to go the the closing } of  the section.  It does not stop anything.

If you want to stop ongoing code, you need to create an Interrupt when a key is pressed, and use that interrupt to stop the ongoing code.


understand. in order to stop the subroutine 1 under case 1 so that it can jump to case 2 for subroutine 2, i need to create an interrupt. for arduino uni, the interrupt in on pin 2 & pin 3. in your opinion, can these 2 pins handle interrupt for 12 case for keypad 3x4. i guess it not possible. by the way, my programming skill is just beginner. i just try & error. by doing that, i learn a little bit. i'm not studying programming language. this is just my interest.

CrossRoads

I think you could create an interrupt with 3 or 4 diodes - When keys are pressed, I think the Row or Column pin goes low - so put the anode on the row or columns, the cathodes all go to the interrupt pin with its internal pullup resistor enabled.
When any of the row (or column) keys is pressed, the diode goes low pulling the interrupt pin 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.

mr_hacker90


I think you could create an interrupt with 3 or 4 diodes - When keys are pressed, I think the Row or Column pin goes low - so put the anode on the row or columns, the cathodes all go to the interrupt pin with its internal pullup resistor enabled.
When any of the row (or column) keys is pressed, the diode goes low pulling the interrupt pin low.



i got what your mean. either keypad column pins or row pins common connected to the diodes. but, due to the lack of programming language knowledge, i found it quite difficult. i guess i have to cheat to my mom. haha... before press keypad, need to press reset button first. haha...

mr_hacker90

by the way CrossRoads, do you have an example code for interrupt. i guess i should have a look first before i just give up. thank you, CrossRoads.

Go Up