Microbit post 2

At the very start u set battery percentage to %100. Then I let button A restart the battery percentage to %100 if pressed. I put if the battery is less than 30% then it means the system must stop. I put pause 30000ms because it represents the 30 seconds that it takes to drain -1% of the battery percentage. I programmed the system to show current battery percentage every time the battery drains –1%. If battery percentage is at 30% conditional statement will run and show ‘’your phone is nearly dead!  System Shut Down! Which also shuts downs your system.

On start set battery percentage to 100: at the very start battery percentage starts at %100

On button [A] pressed set battery percentage to 100: If pressed on button [A] recharge the counter to %100

[Forever]: always same

If %30< battery percentage then

Pause 30000ms

Change battery percentage by –1

Show string battery percentage

Else if battery percentage= %30 then stop/shut down

Show string ‘’your phone is nearly dead! System shut down!


{Java Script}

input.onButtonPressed(Button.A, function () {

Battery_percentage = 100


let Battery_percentage = 0

Battery_percentage = 100

basic.forever(function () {

if (30 < Battery_percentage) {


Battery_percentage += -1

basic.showString(“” + Battery_percentage)

} else if (Battery_percentage == 30) {

basic.showString(“your phone is nearly dead! System shut down!”)




Leave a Reply

Your email address will not be published. Required fields are marked *