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) ......
Files are uploaded to the wiki using the Add Images or other files feature. The namespace in which the files are uploaded is of the type : pm: prj20 ??: c? or : pm: prj20 ??: c?: Student_name (if applicable). Example: Dumitru Alin, 331CC → : pm: prj2009: cc: dumitru_alin .