Introduction to MicroPython - 2 & Dice

Lesson 29/38 | Study Time: 5 Min
Introduction to MicroPython - 2 & Dice

Lesson Overview


Unlike MakeCode, Python on the Micro:bit doesn’t have event blocks like ‘on button A pressed’. Instead, we use the infinite ‘while true’ loop to keep checking if a button has been pressed (actually, MakeCode programs do the same thing when they run on your Micro:bit, but MakeCode hides the infinite loop from you when you’re writing your code). 

So far, we have created code that makes the device do something. This is called output. However, we also need the device to react to things. Such things are called inputs. It’s easy to remember output is what the device puts out to the world whereas input is what goes into the device for it to process. The most obvious means of input on the Micro:bit are its two buttons, labelled A and B. Somehow, we need MicroPython to react to button presses. 

 

Performance Expectations 

  1. The Micro:bit has two input buttons on the front which you can use to make things happen. Create a code in MicroPython to provide an input using these buttons 
  2. When you press input button A the program reacts by showing a happy face image on the LED display output 
  3. Pressing button B makes a sad face appear 
  4. Students will learn to write the code for dice using python. 

 

Guiding Ideas

  1. Using ‘while true’ and ‘if’ commands create your first input program 

  1. Try other emotion image such as ASLEEP, CONFUSED or MEH 

  1. Design your own 'emoticon' using the LED display 

  1. Use the badge to show if you need help or make class voting badges with ticks or crosses 

  1. Design a way of wearing your Micro:bit badge using thread, or tape (don't use safety pins as the metal could damage your Micro:bit) 

  1. Write the code of dice and check the output. 

 

Disclaimer: All content under this course is customized according to the requirement of an educator/student (K12) filtered from Minecraft Education Edition, MakeCode