Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

One button toggle in C

Status
Not open for further replies.

Erythryo

New Member
Recently I have been building a robot, but I have been thinking of a way to make a one button toggle. I was hypothesizing of using a for loop and adding a bit everytime it was pressed, then it would execute the code inside the for bracket.

Put simply, how could I have the mcu check for an input, delay x amount of time then if the button was still on it would execute the code?
 
Well, the two ways would be to either have the entire program include checking for the button inside the main loop, or you could tie the button to an interrupt pin. When the input toggles, it would interrupt the MCU and execute a specific set of instructions (in this case, a delay follow by reading the state of the pin again to see if it is still pressed).
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top