Being more autonomous
You'll do more things on your own from now on.
Copy the example code from $ZEPHYR_BASE/samples/basic/button
and run it on your board. You'll see that:
- The main program does some setup (gpio and interrupt) then copies the state of the switch
sw0
to the ledled0
. - When the button is pressed, an interrupt is received and a message is printed.
Make sure you understand how the interrupts work, and what the ISR does.
Removing the loop
In order to let the system sleep, you will receive an interrupt both when the button is pressed and when it is released. In the interrupt service routine, you'll copy its state to the led.
Commit and push your code when it's done.
Adding a pause
We now want a different behaviour: when the button is pressed, the led will light up. It will go down one second later, unless the button is pressed again in the meantime.
Of course you do not want to use k_sleep()
in an interrupt callback routine. You will use a workqueue in which you'll submit delayable work. You can use the system workqueue, or you can start your own in a new thread.