... | @@ -89,7 +89,7 @@ If you don't remember how to flash code to your Micro::Bit, see the instructions |
... | @@ -89,7 +89,7 @@ If you don't remember how to flash code to your Micro::Bit, see the instructions |
|
<summary>
|
|
<summary>
|
|
JavaScript Base Code (Click to Expand)
|
|
JavaScript Base Code (Click to Expand)
|
|
</summary>
|
|
</summary>
|
|
![fitTrack_base](/uploads/786eb653617a6cd3d1cd105232b6dfc5/fitTrack_base.PNG)
|
|
<img src=/uploads/786eb653617a6cd3d1cd105232b6dfc5/fitTrack_base.PNG>
|
|
<pre>
|
|
<pre>
|
|
let X_Accel = 0
|
|
let X_Accel = 0
|
|
let Y_Accel = 0
|
|
let Y_Accel = 0
|
... | @@ -149,6 +149,64 @@ basic.forever(() => { |
... | @@ -149,6 +149,64 @@ basic.forever(() => { |
|
})
|
|
})
|
|
</pre>
|
|
</pre>
|
|
</details>
|
|
</details>
|
|
|
|
<details>
|
|
|
|
<summary>
|
|
|
|
Python Base Code (Click to Expand)
|
|
|
|
</summary>
|
|
|
|
<pre>
|
|
|
|
from microbit import *
|
|
|
|
import radio
|
|
|
|
|
|
|
|
radio.on()
|
|
|
|
radio.config(channel=1)
|
|
|
|
radio.config(power=7)
|
|
|
|
x_Accel = 0
|
|
|
|
# Initialize y and z acceleration
|
|
|
|
|
|
|
|
measuring = False
|
|
|
|
display.show(Image.YES)
|
|
|
|
|
|
|
|
def capture_data():
|
|
|
|
x_Accel = accelerometer.get_x()
|
|
|
|
# Get y and z acceleration
|
|
|
|
|
|
|
|
radio.send(str(x_Accel) + ',' + str(y_Accel) + ',' + str(z_Accel))
|
|
|
|
|
|
|
|
|
|
|
|
def write_data():
|
|
|
|
print(x_Accel, y_Accel, z_Accel, sep=',', end='\n')
|
|
|
|
|
|
|
|
while True:
|
|
|
|
if button_a.is_pressed() and button_b.is_pressed():
|
|
|
|
# Set measuring to False
|
|
|
|
|
|
|
|
# Send "done" over radio
|
|
|
|
|
|
|
|
# Show a Happy face on the display (display.show(Image.HAPPY))
|
|
|
|
|
|
|
|
elif button_a.is_pressed():
|
|
|
|
# Set measuring to True
|
|
|
|
|
|
|
|
# Show a heart on the display (Image.HEART)
|
|
|
|
|
|
|
|
elif button_b.is_pressed():
|
|
|
|
# Set measuring to False
|
|
|
|
|
|
|
|
# Show a checkmark on the display (Image.YES)
|
|
|
|
|
|
|
|
incoming = radio.receive()
|
|
|
|
if incoming is not None:
|
|
|
|
if incoming.startswith('done'):
|
|
|
|
display.show(Image.HAPPY)
|
|
|
|
print("done")
|
|
|
|
else:
|
|
|
|
x_Accel, y_Accel, z_Accel = incoming.split(",")
|
|
|
|
write_data()
|
|
|
|
if measuring:
|
|
|
|
capture_data()
|
|
|
|
sleep(200)
|
|
|
|
</pre>
|
|
|
|
</details>
|
|
|
|
|
|
## Step 6: Programming!
|
|
## Step 6: Programming!
|
|
1. Read through the links under the prerequisite skills section. This will enable you to understand the basics of the lab. You want to be able to answer the following questions:
|
|
1. Read through the links under the prerequisite skills section. This will enable you to understand the basics of the lab. You want to be able to answer the following questions:
|
... | | ... | |