MakeCode Coding Cards

    Coding cards are small snippets of code that can be used to explore different concepts. They are not meant to be used as they are, but for you to tweak the numbers and combine the cards to get the expected result.

    In this article, the cards are listed below by the hardware output in use, represented with a pink icon. Get creative! Try the card in MakeCode for yourself and modify the program.

    Blink

    Use a loop to alternate between turning the RGB LED "A" on or off. Control the rhythm of the blinking by changing the duration of the pauses.

    Coding Card in MakeCode

    Back and Forth

    Continuously transition the Servo "A" position from one end to the other.

    Coding Card in MakeCode

    Change Color 10 Times

    Alternate between two colors of the RGB LED "A" 10 times before turning it off.

    Coding Card in MakeCode

    Wave 10 Times

    Alternate between two positions of the Servo "A" 10 times.

    Coding Card in MakeCode

    Gradually Change Brightness

    Create a variable "brightness" to store a value and then continuously set the RGB LED "A" brightness to its value. Every time the Button "A" is pressed, increment the variable by 4 units, and constrain it so that its value doesn't go over 100.

    Coding Card in MakeCode

    Gradually Change Position

    Create a variable "position" to store a value and then continuously set the Servo "A" position to its value . Every time the Button "A" is pressed, increment the variable by 4 units, and constrain it so that its value doesn't go over 100.

    Coding Card in MakeCode

    Shine in the Dark

    Use a forever loop to continuously check if the value of the built-in light sensor is below a threshold, and depending on it, turn the RGB LED "A" on or off.

    Coding Card in MakeCode

    Move in the Dark

    Continuously set the position of the Servo "A" to the value of the light sensor, constrained from 0 to 100 (since the light level goes up to 255).

    Coding Card in MakeCode

    Color Party

    Use a loop to continuously set the hue of the RGB LED "A" to a random value and change its color.

    Coding Card in MakeCode

    Shake

    Repeatedly set the Servo "A" position to a random value.

    Coding Card in MakeCode

    Rainbow

    Smoothly change the RGB LED "A" color, by iterating over different hue values from 0 to 100.

    Coding Card in MakeCode

    Sweep

    Continuously iterate over a number from 0 to 100 and use it to set the position of the Servo "A".

    Coding Card in MakeCode

    Loop Over a List of Colors

    Create a list of colors and then continuously loop through them and set their value to the RGB LED.

    Coding Card in MakeCode

    Loop Over a List of Positions

    Create a list of positions and then continuously loop through them and set their value as the position to the Servo "A".

    Coding Card in MakeCode

    Light Switch

    Use a "toggle" variable to store the state of the RGB LED "A". 1 means on, and 0 means off.

    When the Button "A" is pressed, use an if statement to check the value of the variable and then, depending on the value, turn the led on or off, and toggle the value stored inside the variable.

    Coding Card in MakeCode

    Press Button to Toggle Position

    Use a "toggle" variable to store the state of the Servo "A" position. 1 means one position, and 0 means another.

    When the Button "A" is pressed, use an if statement to check the value of the variable and then, depending on the value, set the position of the servo to 20 or 80, and toggle the value stored inside the variable.

    Coding Card in MakeCode

    Tilt to Change Color

    Continuously store the value of the "x" axis of the accelerator in the variable "movement". Since the accelerator gives readings in the range -1023 to 1023, use a map to convert it to the range 0 to 100 and store it in the "hue" variable. Set the hue of the RGB LED "A" to the value of the "hue" variable.

    Coding Card in MakeCode

    Tilt to Move

    Continuously store the value of the "x" axis of the accelerator in the variable "movement". Since the accelerator gives readings in the range -1023 to 1023, use a map to convert it to the range 0 to 100 and store it in the "position" variable. Set the Servo "A" to the value of the "position" variable.

    Coding Card in MakeCode

    Light Alarm

    Continuously turn off the RGB LED "A" and monitor the acceleration strength for motion detection. If it goes over 1200, turn on the RGB LED "A" for 4 seconds.

    Coding Card in MakeCode

    Move when Moved

    Continuously monitor the acceleration strength for motion detection. If it goes over 1200, transition the Servo "A" position back and forth.

    Coding Card in MakeCode

    Change Color While Pressing Button

    Use a loop to continuously check if Button "A" is pressed, and then set the color of the RGB LED "A" to either red (when pressed) or blue (while not pressed).

    Coding Card in MakeCode

    Change Position While Pressing Button

    Use a loop to continuously check if Button "A" is pressed, and then set the color position of the Servo "A" to either 0 (when pressed) or 100 (while not pressed).

    Coding Card in MakeCode

    Send/Receive Color

    Use two Robotics Boards with one acting as a sender of radio values and the other as a receiver.

    Sender

    Set the radio group to 1, to connect with the receiver. Continuously check if Button "A" is pressed then send a radio signal with the name "light" and the value to turn the light on or off.

    Sender Coding Card in MakeCode

    Receiver

    Set the radio group to 1, to connect with the sender. Monitor the incoming radio signals named "light" and use its value the set one of the components of the RGB LED "A" color.

    Receiver Coding Card in MakeCode

    Remote Control Motor Sender and Receiver

    Use two Robotics Boards with one acting as a sender of radio values and the other as a receiver.

    Sender

    Set the radio group to 1, to connect with the receiver. Continuously send the number value of the readings from the accelerator "y" axis, converted from the range -1023 to 1023 (raw data) to 0 to 100 (valid servo positions).

    Sender Coding Card in MakeCode

    Receiver

    Set the radio group to 1, to connect with the sender. Monitor the incoming radio number and use it to set the Servo "A" position.

    Receiver Coding Card in MakeCode

    Download

    Download the collection of coding cards to print or share digitally with students.

    micro:bit Coding Cards