... | @@ -84,7 +84,71 @@ def capture_data(): |
... | @@ -84,7 +84,71 @@ def capture_data(): |
|
|
|
|
|
|
|
|
|
## Step 5: Flash the base code
|
|
## Step 5: Flash the base code
|
|
If you don't remember how to flash code to your Micro::Bit, see the instructions [here](how-to-flash).
|
|
If you don't remember how to flash code to your Micro::Bit, see the instructions [here](how-to-flash). The base code is also given below.
|
|
|
|
<details>
|
|
|
|
<summary>
|
|
|
|
JavaScript Base Code (Click to Expand)
|
|
|
|
</summary>
|
|
|
|
![fitTrack_base](/uploads/786eb653617a6cd3d1cd105232b6dfc5/fitTrack_base.PNG)
|
|
|
|
<pre>
|
|
|
|
let X_Accel = 0
|
|
|
|
let Y_Accel = 0
|
|
|
|
let Z_Accel = 0
|
|
|
|
let measuring = false
|
|
|
|
radio.onDataPacketReceived(({ receivedString: name, receivedNumber: value }) => {
|
|
|
|
if (name == "x") {
|
|
|
|
X_Accel = value
|
|
|
|
} else if (name == "y") {
|
|
|
|
// Set the y acceleration to value
|
|
|
|
|
|
|
|
} else if (name == "z") {
|
|
|
|
// set the z acceleration to value
|
|
|
|
|
|
|
|
write_data()
|
|
|
|
} else if (name == "done") {
|
|
|
|
serial.writeLine("done")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
input.onButtonPressed(Button.AB, () => {
|
|
|
|
radio.sendValue("done", 0)
|
|
|
|
// Set measuring to false
|
|
|
|
|
|
|
|
// Show a happy face on the display
|
|
|
|
|
|
|
|
})
|
|
|
|
input.onButtonPressed(Button.A, () => {
|
|
|
|
// Set measuring to true
|
|
|
|
|
|
|
|
// Show a heart on the display
|
|
|
|
|
|
|
|
})
|
|
|
|
input.onButtonPressed(Button.B, () => {
|
|
|
|
// Set measuring to false
|
|
|
|
|
|
|
|
// Show check mark (yes icon) on the display
|
|
|
|
})
|
|
|
|
function capture_data() {
|
|
|
|
X_Accel = input.acceleration(Dimension.X)
|
|
|
|
// Set the y and z accelerations to the y and z dimensions
|
|
|
|
|
|
|
|
radio.sendValue("x", X_Accel)
|
|
|
|
// Send y and z values over radio
|
|
|
|
|
|
|
|
}
|
|
|
|
function write_data() {
|
|
|
|
serial.writeLine("" + X_Accel + "," + Y_Accel + "," + Z_Accel)
|
|
|
|
}
|
|
|
|
radio.setGroup(1)
|
|
|
|
radio.setTransmitPower(7)
|
|
|
|
basic.showIcon(IconNames.Yes)
|
|
|
|
basic.forever(() => {
|
|
|
|
if (measuring) {
|
|
|
|
capture_data()
|
|
|
|
basic.pause(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:
|
... | | ... | |