This is an old revision of the document!
Moad Asehraoui 1220 AF
It counts how many times the micro:bit has been shaken and if the acceleration is greater than (>) 1000, It stores this number in a variable called ‘steps’, every time the micro:bit accelerometer input senses a shake, the program increases the variable by 1, and shows the new number on the LED display output.
Once the steps reache 10 steps, the varibale called 'Calories' will be increqsed by 40.4 and the distance as well with 0.0006.
To restart the game, you press at A, and to stop the program and display the results, you press at B, it starts and stops after hearing a music from the speaker of the microbit.
The conceptual scheme of the project is as follows:
Description of the application code (firmware):
While true : if accelerometer.get_y() > 1000: steps += 1 counter2 += 1 display.scroll(steps) if counter2 == 10: calories = calories + 40.4 distance += 0.0006 speed = accelerometer.get_y() counter2 = 0
The functions for Button A and B :
if button_a.is_pressed(): music.play(music.POWER_UP) display.scroll("restart") sleep(300) calories = 0 distance = 0 steps = 0 counter = 0 counter2 = 0 time1 = running_time() if button_b.is_pressed(): time2 = running_time() time = (time2 - time1)/1000 music.play(music.POWER_DOWN) display.scroll("Duration:") display.scroll(time) sleep(300) ......
Link of the Video :
Drive : https://drive.google.com/file/d/13ngXFNZwSfSHbOHqf-ctTG2ivulbxQru/view?usp=sharing
Youtube : https://youtu.be/Hnfv7vRd2BI
The code :