Extend it with code

How can you improve it?

If you’ve made it this far then you should be up for a challenge. You’ve got the hang of buttons and touch pins so why not attempt the following challenges:

  • Write a program that shows a happy face if you push one button and a sad face if you push another.

    Hint: Use the documentation to remind you how to show an image. You might want to put your code in a while True  loop so that it keeps repeating.

  • Make a countdown timer where you use the buttons to set the time then touch pin0 to count down to 0.

    Hint: Use sleep(1000)  to make your program pause for a second. You’ll need a variable that stores the countdown value.

  • Adapt the micro:vote counter from the previous page so that you can choose any of 4 options with one button then select your choice with the other button.

    Hint: You’ll need a variable that stores the option that the user has chosen and you’ll need to store the number of votes for each option separately. You could do this with separate values or a list.