diff --git a/docs/projects/compass.md b/docs/projects/compass.md index f22ffe04..38c6667c 100644 --- a/docs/projects/compass.md +++ b/docs/projects/compass.md @@ -10,12 +10,10 @@ Welcome! This guided tutorial will show you how to program a script that display ### ~ - ## Step 1 Create a loop that will continuously update the reading of the compass. - ```blocks basic.forever(() => { diff --git a/docs/projects/flashing-heart.md b/docs/projects/flashing-heart.md index 95f612b1..40be3ba3 100644 --- a/docs/projects/flashing-heart.md +++ b/docs/projects/flashing-heart.md @@ -2,8 +2,7 @@ ### ~avatar avatar -Use the LEDs to display a flashing heart, and then create -an animation of a broken heart. :( +Use the LEDs to display a flashing heart! ### ~ @@ -38,19 +37,19 @@ basic.clearScreen(); ## Step 3 -Put a [forever loop](/reference/basic/forever) around it. +Put a [forever loop](/reference/basic/forever) around it to repeat the animation. ```blocks basic.forever(() => { -basic.showLeds(` - . # . # . - # # # # # - # # # # # - . # # # . - . . # . .` - ); -basic.pause(500); -basic.clearScreen(); + basic.showLeds(` + . # . # . + # # # # # + # # # # # + . # # # . + . . # . .` + ); + basic.pause(500); + basic.clearScreen(); }) ``` @@ -60,45 +59,50 @@ Add a [pause](/reference/basic/pause) to wait after clearing the screen. ```blocks basic.forever(() => { -basic.showLeds(` - . # . # . - # # # # # - # # # # # - . # # # . - . . # . .` - ); -basic.pause(500); -basic.clearScreen(); -basic.pause(500); + basic.showLeds(` + . # . # . + # # # # # + # # # # # + . # # # . + . . # . .` + ); + basic.pause(500); + basic.clearScreen(); + basic.pause(500); }) ``` -## Step 5 +## Send your heartbeats over radio! -Add a second image of a broken heart. +Do you have a second @boardname@ at hand? You could use radio and send your heartbeats to other +@boardname@ and show a heart when you receive one. +* move the code in the **forever** inside +a [on data packet received](/reference/radio/on-data-packet-received) handler. +The handler will run whenever a message is received from another @boardname@. +* use [send number](/reference/radio/send-number) and [pause](/reference/basic/pause) +to broadcast a packet of data every second. ```blocks basic.forever(() => { -basic.showLeds(` - . # . # . - # # # # # - # # # # # - . # # # . - . . # . .` - ); -basic.pause(500); -basic.clearScreen(); -basic.pause(500); -basic.showLeds(` - . # . # . - # . # # # - # . . . # - . # # # . - . . # . .` - ); -basic.pause(500); -basic.clearScreen(); -basic.pause(500); + radio.sendNumber(0) + basic.pause(1000) +}) +radio.onDataPacketReceived(({receivedNumber}) => { + basic.showLeds(` + . # . # . + # # # # # + # # # # # + . # # # . + . . # . .`); + basic.pause(500) + basic.clearScreen() + basic.pause(500) }) ``` + +Download the .hex file onto both @boardname@ and try it out! + +```package +radio +``` \ No newline at end of file diff --git a/docs/projects/smiley-buttons.md b/docs/projects/smiley-buttons.md index f7eb51cb..20a65108 100644 --- a/docs/projects/smiley-buttons.md +++ b/docs/projects/smiley-buttons.md @@ -12,8 +12,8 @@ Use [show leds](/reference/basic/show-leds) to make a smiley face: ```blocks basic.showLeds(` - . # . # . - . # . # . + # # . # # + # # . # # . . . . . # . . . # . # # # .` @@ -22,56 +22,89 @@ basic.showLeds(` ## Step 2 -Add an input block for when [button A is pressed](/reference/input/button-is-pressed), and put a -frowny face inside it: +Add an input block for when [button A is pressed](/reference/input/button-is-pressed), +and **move** the smiley face inside it: ```blocks -basic.showLeds(` - . # . # . - . # . # . - . . . . . - # . . . # - . # # # .` - ); input.onButtonPressed(Button.A, () => { basic.showLeds(` - . # . # . - . # . # . - . . . . . - . # # # . - # . . . #` - ); -}); -``` - -## Step 3 - -Now add blocks so that when [button B is pressed](/reference/input/button-is-pressed), a smiley appears: - -```blocks -basic.showLeds(` - . # . # . - . # . # . - . . . . . - # . . . # - . # # # .` - ); -input.onButtonPressed(Button.A, () => { - basic.showLeds(` - . # . # . - . # . # . - . . . . . - . # # # . - # . . . #` - ); -}); -input.onButtonPressed(Button.B, () => { - basic.showLeds(` - . # . # . - . # . # . + # # . # # + # # . # # . . . . . # . . . # . # # # .` ); }); ``` + +Try pressing button A! + +## Step 3 + +Now add blocks so that when [button B is pressed](/reference/input/on-button-pressed), +a frowney appears: + +```blocks +input.onButtonPressed(Button.A, () => { + basic.showLeds(` + # # . # # + # # . # # + . . . . . + # . . . # + . # # # .` + ); +}); +input.onButtonPressed(Button.B, () => { + basic.showLeds(` + # # . # # + # # . # # + . . . . . + . # # # . + # . . . #` + ); +}); +``` + +Try pressing ``A`` or ``B``! + +## Send your smileys over radio + +Do you have a second @boardname@ at hand? You could use radio and send your smileys or frownies to other +@boardname@. + +Since radio can send numbers, we decide that ``0`` is the code for displaying a smiley +and ``1`` is the code for a frowney. + +Change your code as follows: +* [radio send number](/reference/radio/send-number) sends a number +to any other @boardname@ in range +* [radio on data packet received](/reference/radio/on-data-packet-received) runs code +when data is received over radio + +```blocks +input.onButtonPressed(Button.A, () => { + radio.sendNumber(0) +}) +input.onButtonPressed(Button.B, () => { + radio.sendNumber(1) +}) +radio.onDataPacketReceived(({receivedNumber}) => { + if (receivedNumber == 0) { + basic.showLeds(` + # # . # # + # # . # # + . . . . . + # . . . # + . # # # . + `) + } else { + basic.showLeds(` + # # . # # + # # . # # + . . . . . + . # # # . + # . . . # + `) + } +}) +``` \ No newline at end of file