🤖
KidsCode
  • Welcome to KidsCode
  • Setting up mBlock
  • Arduino Lessons
    • Arduino Beginner Lessons
      • Blinking an LED
      • LED Switching
      • LED Chasing
      • Traffic Signal
      • Buzzer
      • Buzzer + Push Button
      • LED + Push Button
    • Bluetooth LED
  • Arduino Robot Car
    • Arduino Bluetooth Car
      • What you will need
      • Circuit Diagram
      • Assembly the Car
      • Upload the Code
      • Bluetooth setup and Test
  • Micro:bit Beginners
    • micro:bit, the hardware
    • Overview of MakeCode
    • Video Library
    • Lesson 1
      • My micro:bit
      • Safety first!
      • Plug in your micro:bit
      • My name is?
      • Learning Outcomes
    • Lesson 2
      • Whats your name again?
      • How fast is your heart beat?
    • Lesson 3
      • Please switch on the TV
      • One, Two, Three
      • Keep pressing that buttons
    • Lesson 4
      • Variable, what is that!!
      • Step Counter
      • 1 + 1 = 2
  • Micro:bit Advanced Activities
    • Blinking an LED
    • Traffic Signal
Powered by GitBook
On this page
  • Create your new program
  • Save, download and run your code

Was this helpful?

  1. Micro:bit Beginners
  2. Lesson 4

1 + 1 = 2

PreviousStep CounterNextBlinking an LED

Last updated 5 years ago

Was this helpful?

Teachers Notes

In this lesson, the kids will learn how to assign variable to each button and perform an addition function.

  • Assign a variable to button A

  • Assign a variable to button B

  • Value for each variable will be assigned based on number of taps on the particular button

  • When A+B is pressed, the LED's will show the sum of values of variables A and B

  • Shaking the micro:bit will reset the variables

Create your new program

Click on the micro:bit icon on your toolbar or go to on your browser.

Click on "New Project". The MakeCode editor will appear

Delete the forever blocks by dragging it to the toolbar. Click on Variables option from the toolbar

Click Make a Variable and give it a name "A"

Click Ok. The variable A will now be created

Follow the same steps again to create variable "B"

Now you will have to initialize variables on start. Drag set variable to 0 option to the on start block. Select the dropdown and select variable A. Similarly pefrorm the same step for variable B.

Now we have initialized the variable. We will have to now make code for the variable to assign values based on number of taps we perform on a button. If we press button A the variable A should increase value by 1

To perform this function, drag on button A pressed option from Input toolbar. From the Variables toolbar, drag change A by option and change the value to 1.

Repeat the same step for button B

Now we must perform the addition function when button A and B are pressed together. Drag the on button A+B pressed option from the Input toolbar

Drag show string option from the Basic Toolbar

Now we will have to perform a mathematical calculation of the variables. Open the Math toolbar and drag 0 + 0 option to the code editor

Now replace the zeros with variables A and B by dragging A and B from the Variables toolbar

Now you must be able to reset the calculator after addition function is completed. We can reset the variables as we shake the micro:bit. To perform this function drag on shake option from Input toolbar. Add set A to 0 and set B to 0 options to on shake from Variables toolbar

Save, download and run your code

Save you code as Calculator and press save to download.

Drag your code file named microbit-1-2-3.hex to the MICROBIT(D:) folder to upload your code to your micro:bit.

Test your micro:bit by pressing Button A once, then Button B once then both button A and button B at the same time. Your micro:bit will add 1 + 1 and display value 2

https://makecode.microbit.org/