micro:bit for primary schools – mb4ps.co.uk Sessions 4 and 5 – PXT Editor update Animations and brightness Written by Neil Rickus. Licensed under CC BY-NC-SA 4.0
Objectives Alter the brightness of the LEDs Use a variable to alter the brightness Trigger events with the buttons
Altering LED brightness Last time we made an animation We’re now going to make a heart fade in What blocks do you think we could use?
Altering LED brightness These instructions will make a heart flash
Challenges Make your heart fade in more gradually Get the LEDs to dim, then go brighter
Using variables We can use a variable to store the brightness Create a new variable called “myBrightness” by clicking on Make a Variable from the Variables block We’ll then set this variable to zero when the program starts
Using variables Through using the variables, we can reduce the number of instructions we need
Challenges Alter the speed of the fade by: Changing the length of the pause Altering the brightness increase
Programming events We can make the heart only appear when you shake the device
Challenges Make the heart go brighter if you press button A – try this block Make the heart go darker if you press button B Make the heart vanish if you press A and B at the same time Make the heart go brighter if you tilt the micro:bit screen upwards Make the heart go darker if you tilt the micro:bit screen downwards