Skip to content

نشاط

عدّاد الخطوات

مبتدئ | MakeCode, Python | شاشة LED, مقياس التسارع | أجهزة الاستشعار, أدوات الأداء, الجسم البشري, الضرب, القياس, المتغيرات

الخطوة 1: اصنعها

ماذا يعني؟

حوّل المايكروبيت إلى عداد خطوات (أو مقياس مسافة السير) ليساعدك في تتبع نشاطك وتعلم البرمجة في نفس الوقت!

هذان الفيديوهان يعرضان لك ما ستصنعه وكيفية برمجته:

مقدمة

دليل البرمجة

كيف يعمل؟

  • حمل البرمجية على المايكروبيت وأرفق حزمة البطارية
  • Attach the micro:bit and battery pack to your shoe or ankle, place it inside your sock, or just hold it in your hand and shake it as you walk.
  • The code uses the micro:bit’s accelerometer sensor input to sense when your leg is moving.
  • The code counts how many times the micro:bit has been shaken. It stores this number in a variable called ‘steps’.
  • Variables are containers for storing data, which can be accessed and updated while a program is running.
  • Every time the micro:bit accelerometer input senses a shake, the program increases the number held in the variable by 1, and shows the new number on the LED display output.

ما تحتاجه

  • المايكروبيت (micro:bit) (أو محاكي MakeCode)
  • محرر MakeCode أو Python
  • battery pack
  • something to attach the micro:bit to your shoe or leg – elastic band, a pipe cleaner, tape or Velcro.

الخطوة 2: برمجها

1from microbit import *
2steps=0
3
4while True:
5    if accelerometer.was_gesture('shake'):
6        steps += 1
7        display.show(steps)

الخطوة 3: حسّنها

  • Modify the code so it shows your current step count when you press a button.
  • If you find that the code only counts every other step, modify the code to multiply the ‘steps’ variable by two when it’s displayed.
  • Measure the length of your average stride and get your micro:bit to multiply this by the number of steps to calculate the distance you’ve walked.
فتاة تشير إلى عداد خطوات مايكروبت (micro:bit) على حذاء فتاة أخرى