From 350a98b429b2634dc99bdc3be2d2bdf6f788c30d Mon Sep 17 00:00:00 2001 From: Galen Nickel Date: Mon, 27 Nov 2017 19:14:03 -0800 Subject: [PATCH] Fixes to a couple of projects (#573) * local commit * Fixes to a couple of projects --- docs/projects/banana-keyboard.md | 4 +- docs/projects/banana-keyboard/code.md | 73 +++++++++------ docs/projects/banana-keyboard/make.md | 42 ++++----- docs/projects/karel.md | 123 ++++++++++++++++---------- docs/projects/milky-monster/code.md | 2 +- 5 files changed, 148 insertions(+), 96 deletions(-) diff --git a/docs/projects/banana-keyboard.md b/docs/projects/banana-keyboard.md index 205f115f..aa26b3ff 100644 --- a/docs/projects/banana-keyboard.md +++ b/docs/projects/banana-keyboard.md @@ -1,4 +1,4 @@ -# banana keyboard +# Banana keyboard ## @description A beginner maker activity, building a piano from bananas. @@ -15,7 +15,7 @@ Build your own @boardname@ piano using bananas! ## Materials * @boardname@, battery holder and 2 AAA batteries -* Bananas +* Banana * Orange * Crocodile clips diff --git a/docs/projects/banana-keyboard/code.md b/docs/projects/banana-keyboard/code.md index c4195061..b4ae8122 100644 --- a/docs/projects/banana-keyboard/code.md +++ b/docs/projects/banana-keyboard/code.md @@ -1,14 +1,16 @@ # Code -Have you ever tried to making beat box sounds? Let's try making a beatbox with code! +Have you ever tried making beat box sounds? Let's try making a beatbox with code and, yes, a banana! -We will register an event handler on the fruit that will execute when two things occur: first, the alligator clip attaches to GND and the other side of the alligator clip is inserted into a banana. Let's start by adding a variable where you can store data. Then rename the variable to "sound". Then set the value of the variable to the note block `A` from the Music drawer. Modify your code so that your code looks like this. +## Code the banana key + +Start by adding a variable to store a musical note. Rename the variable to `sound`. Set the value of the variable to the note block `Middle A` from the **Music** drawer. ```blocks let sound = music.noteFrequency(Note.A); ``` -We want to play music on pin pressed in order to register an event handler that will execute whenever when you run a script and click pin 1 on the simulator. We must start by opening the Input drawer and adding `on pin pressed` P1. Modify your code so that your code looks like this. +We want to play music when the fruit connected to a pin pressed. So, we register an event handler that executes whenever pin **1** is pressed. Pin **1** is, of course, connected to the banana. Add a ``||input:on pin pressed||`` block from the **Input** drawer. ```blocks let sound = music.noteFrequency(Note.A); @@ -17,38 +19,59 @@ input.onPinPressed(TouchPin.P1, () => { }) ``` -We want to code the notes that will be played `on pin pressed`. We click on the Input drawer then insert a `for loop` that will increment by *i*. Click on the Variables drawer. Add `set item` block. Rename the variable block to "sound." Then add a Maths block to increase the variable sound from the note frequency of block `A` to `A` plus 25.Modify your code so that your code looks like this - -```blocks -let sound = music.noteFrequency(Note.A); -input.onPinPressed(TouchPin.P1, () => { - for (let i = 0; i < 4; i++) { - sound = sound + 25 - } -}) -``` - - -* click *Download* to see if the code works as expected. - - - -Let's include a second sound `on pin pressed` *P2*. To do this, you need to add the same blocks as the banana keyboard activity. However, you must change alter `on pin pressed` from P1 to P2. Additionally, you must *decrease* the frequency of the variable "sound" by 25. Modify your code so that your code looks like this. You will need to include a second banana to a alligator (spring) clip in the same procedure as the first activity. +Now, let's create some notes to play when the banana is pressed. Click on the **Loops** drawer then insert a ``||loops:repeat||`` loop into the ``||input:on pin pressed||`` block. Click on the **Variables** drawer and pull out a ``||variables:change item by||`` block and put it into the loop. Rename the variable to `sound`. Change the value from `1` to `25`. This will increase the variable `sound` from the note frequency of block `Middle A` to `Middle A` plus 25 and so on. Put a ``||variables:set to||`` block for `sound` right after the loop. Set it to `Middle A` a in order to reset the sound after a banana press. ```blocks let sound = music.noteFrequency(Note.A); input.onPinPressed(TouchPin.P1, () => { for (let i = 0; i < 4; i++) { - sound = sound + 25 + sound += 25; } -}) + sound = music.noteFrequency(Note.A); +}); +``` + +Finally, insert a ``||music:play tone||`` above the ``||variables:change by||``. Pull out the ``sound`` variable block and drop it in the note slot of ``||music:play tone||``. Change the beat fraction from `1` to `1/4`. + +```blocks +let sound = music.noteFrequency(Note.A); + +input.onPinPressed(TouchPin.P1, () => { + for (let i = 0; i < 4; i++) { + music.playTone(sound, music.beat(BeatFraction.Quarter)); + sound += 25; + } + sound = music.noteFrequency(Note.A); +}); +``` + +Click `|Download|` and try a banana press. Did you hear 4 notes play? + + +## Add another banana key +Go back to **[Make](/projects/banana-keyboard/make)** and repeat steps 7 and 8 with another banana but this time connect the crocodile clip to pin **3**. + +Duplicate the ``||input:on pin pressed||`` event handler to make a second one. For the new ``||input:on pin pressed||``, change the pin name to **P2**. In the pin **P2** event, let's have the the frequency in the variable `sound` decrease by 25 instead of having it increase. Change the `25` in the ``||variables:change by||`` block to `-25`. OK, your code now looks like this: + +```blocks +let sound = music.noteFrequency(Note.A); + +input.onPinPressed(TouchPin.P1, () => { + for (let i = 0; i < 4; i++) { + music.playTone(sound, music.beat(BeatFraction.Quarter)); + sound += 25; + } + sound = music.noteFrequency(Note.A); +}); input.onPinPressed(TouchPin.P2, () => { for (let i = 0; i < 4; i++) { - sound = sound - 25 + music.playTone(sound, music.beat(BeatFraction.Quarter)); + sound += -25; } -}) + sound = music.noteFrequency(Note.A); +}); ``` -* click *Download* to see if the code works as expected. +Click `|Download|` again and play both bananas. It's a fruit jam session! diff --git a/docs/projects/banana-keyboard/make.md b/docs/projects/banana-keyboard/make.md index f6a23454..2c400814 100644 --- a/docs/projects/banana-keyboard/make.md +++ b/docs/projects/banana-keyboard/make.md @@ -3,73 +3,73 @@ ## Materials * @boardname@, battery holder and 2 AAA batteries -* Bananas +* Banana * Orange -* Crocodile clips +* 4 Crocodile clips ## Steps -## Step 1 +### ``|Step 1|`` - Connect the ground lead ![](/static/mb/lessons/banana-keyboard-1.png) -Using the 1st crocodile clip, connect the end of the crocodile clip onto GND pin on the @boardname@. +Using the **1st** crocodile clip, connect the end of the crocodile clip onto **GND** pin of the @boardname@. -## Step 2 +### ``|Step 2|`` - Connect the sound lead ![](/static/mb/lessons/banana-keyboard-2.png) ![](/static/mb/lessons/banana-keyboard-3.png) -Using the 2nd crocodile clip, connect the end of the crocodile clip onto the 0 pin on the @boardname@. +Using the **2nd** crocodile clip, connect the end of the crocodile clip onto pin **0** of the @boardname@. -## Step 3 +### ``|Step 3|`` - Connect the headphone to ground ![](/static/mb/lessons/banana-keyboard-4.png) -Using the 1st crocodile clip, connect the second end of the crocodile clip onto based of the headphone jack. +Using the **1st** crocodile clip, connect the second end of the crocodile clip onto based of the headphone jack. -## Step 4 +### ``|Step 4|`` - Connect the headphone sound contact ![](/static/mb/lessons/banana-keyboard-5.png) ![](/static/mb/lessons/banana-keyboard-6.png) -Using the 2nd crocodile clip, connect the second end of the crocodile clip onto tip of the headphone jack. +Using the **2nd** crocodile clip, connect the second end of the crocodile clip onto tip of the headphone jack. -## Step 5 +### ``|Step 5|`` - Connect a fruit lead ![](/static/mb/lessons/banana-keyboard-7.png) -Using the 3rd crocodile clip, connect the end of the crocodile clip onto the 1st crocodile clip already clipped onto GND. +Using the **3rd** crocodile clip, connect the end of the crocodile clip onto the **1st** crocodile clip already clipped onto **GND**. -## Step 6 +### ``|Step 6|`` - Connect the orange to ground ![](/static/mb/lessons/banana-keyboard-8.png) ![](/static/mb/lessons/banana-keyboard-9.png) -Using the 3rd crocodile clip, connect the unattached end of the crocodile clip onto the orange. +Using the **3rd** crocodile clip, connect the unattached end of the crocodile clip onto the orange. -## Step 7 +### ``|Step 7|`` - Connect a second fruit lead ![](/static/mb/lessons/banana-keyboard-10.png) -Using the 4th crocodile clip, connect the end of the crocodile clip onto pin 1 on the @boardname@. +Using the **4th** crocodile clip, connect the end of the crocodile clip onto pin **1** on the @boardname@. -## Step 8 +### ``|Step 8|`` - Connect the banana ![](/static/mb/lessons/banana-keyboard-11.png) -Using the 4th crocodile clip, connect the unattached end of the crocodile clip onto the banana. +Using the **4th** crocodile clip, connect the unattached end of the crocodile clip onto the banana. -## Step 9 +### ``|Step 9|`` - Complete banana keyboard ![](/static/mb/lessons/banana-keyboard-12.png) Your banana keyboard is ready! -## Step 10 +### ``|Step 10|`` - Test the keyboard Connect your @boardname@ to your computer using your USB cable and run this script: ```blocks @@ -78,7 +78,7 @@ input.onPinPressed(TouchPin.P1, () => { }); ``` -Tap your banana instrument to play sound against... the fruit! +Grab a the orange with one hand. With the fingers of your other hand, tap the banana to play sound. Your banana keyboard is ready! ## ~button /projects/banana-keyboard/code NEXT: beat box diff --git a/docs/projects/karel.md b/docs/projects/karel.md index 2352659b..ac15c2cc 100644 --- a/docs/projects/karel.md +++ b/docs/projects/karel.md @@ -10,63 +10,94 @@ Help Karel make LED art! ![](/static/mb/projects/karel/hi.png "Hi") -The goal of this activity is to download the JavaScript code given below onto a board, -then USE the program to introduce new students to the @boardname@. -Students will not do the coding this time. They will be users to get familiar with the board. +The goal of this activity is to download the JavaScript code given below onto a @boardname@. +Then USE the program to introduce new students to the @boardname@. +Students will not do the coding this time. They will be the users who get familiar with the board. ## How to play * ``A button`` **Turn Left** -Does not draw anything just changes the direction Karel (the flashing led) is facing +>Does not draw anything just changes the direction Karel (the flashing led) is facing * ``B button`` **Move Forward** -Moves Karel forward one step and leaves the LED on behind him +>Moves Karel forward one step and leaves the LED on behind him * ``shake`` **Jump** -Moves Karel forward one step without leaving the LED on behind him +>Moves Karel forward one step without leaving the LED on behind him * ``A+B button`` **Hide Karel** -Shows or hides Karel (the flashing LED), to be used once your artwork is complete +>Shows or hides Karel (the flashing LED), to be used once your artwork is complete * ``Reset button`` **Clear the board and restart** -Restart the program and clear the board +>Restart the program and clear the board -Note, that there is no way to erase, other than restarting. +**Note:** There is no way to erase, except by restarting. -## ~ +## Try drawing some patterns -See if you can make each pattern below using A, B, and shake. Once you have completed a challenge press A and B at the same time to hide Karel. -For patterns that you design decide which LEDs you want to turn on and then make that design with Karel. +See if you can make each pattern below using **A**, **B**, and **shake**. Once you have completed a challenge press **A** and **B** at the same time to hide Karel. +For patterns that you design, decide which LEDs you want to turn on and then make that design with Karel. -## Spiral +### Spiral ![](/static/mb/projects/karel/spiral.png "Spiral") -## Right turn +### Right turn ![](/static/mb/projects/karel/right-turn.png "Right turn") -## Eyes +### Eyes ![](/static/mb/projects/karel/eyes.png "Eyes") -## Smile +### Smile + ![](/static/mb/projects/karel/smile.png "Smile") -## Check +### Check + ![](/static/mb/projects/karel/check.png "Check") -## First letter of your name -Figure out how to make the first letter of your name with the LEDs. -![](/static/mb/projects/karel/blank.png "Blank") +### First letter of your name -## Your design! -Make something fun! -![](/static/mb/projects/karel/blank.png "Blank") +Figure out how to make the first letter of your name with the LEDs. + +```sim +basic.forever(() => { + basic.showAnimation(` + # # # . . # # # . . # # # . . # # # . . + . . . . . # . . . . # . . . . # . . # . + . . . . . # . . . . # . . . . # . . # . + . . . . . # . . . . # . . . . # . . # . + . . . . . # . . . . # # # . . # # # . . + `) + basic.pause(1000) + basic.clearScreen() + basic.pause(1000) +}) +``` + +### Your design! + +Make something fun! + +```sim +basic.forever(() => { + basic.showAnimation(` + # . . . . # . . . . # . . . . # . . . . # . . . . # . . . . + . . . . . # . . . . # . . . . # . . . . # . . . # # . # # # + . . . . . # . . . . # . . . . # . . . . # . . . # # . # . # + . . . . . # . . . . # . . . . # . . . . # . . . # # . . . # + . . . . . # . . . . # # # # # # # # # # # # # # # # # # # # + `) + basic.pause(1000) + basic.clearScreen() + basic.pause(1000) +}) +``` Thanks for playing with Karel the LED! -## ~ +## Coding Karel the LED + +Copy this code into the JavaScript editor and then download it to the board. ```typescript /** * Karel the LED - * - * Copy this code into the JavaScript editor and program the board. - * Use the instructions above to complete the challenges. */ basic.forever(() => { if (board.isKarelActive) { @@ -155,36 +186,34 @@ class Board { } switch (this.karelDirection) { case Direction.UP: - if (this.karelY > 0) { - this.karelY -= 1; - } - break; + if (this.karelY > 0) { + this.karelY -= 1; + } + break; case Direction.LEFT: - if (this.karelX > 0) { - this.karelX -= 1; - } - break; + if (this.karelX > 0) { + this.karelX -= 1; + } + break; case Direction.DOWN: - if (this.karelY < 4) { - this.karelY += 1; - } - break; + if (this.karelY < 4) { + this.karelY += 1; + } + break; case Direction.RIGHT: - if (this.karelX < 4) { - this.karelX += 1; - } - break; + if (this.karelX < 4) { + this.karelX += 1; + } + break; } } pressedAB() { this.isKarelActive = !this.isKarelActive; } - } ``` +## About the authors - -## about the authors -This project was contributed by Dr. David Fisher a professor at [Rose-Hulman Institute of Technology](http://www.rose-hulman.edu/). Dr. Fisher loves educational robotics and runs various outreach programming activities, including a summar camp, called [Connecting with Code](https://connectingwithcode.org), which gives a @boardname@ to each participant. \ No newline at end of file +This project was contributed by Dr. David Fisher a professor at [Rose-Hulman Institute of Technology](https://www.rose-hulman.edu/academics/faculty/fisher-david-fisherds.html). Dr. Fisher loves educational robotics and runs various outreach programming activities, including a summer camp, called [Connecting with Code](https://connectingwithcode.org), which gives a @boardname@ to each participant. \ No newline at end of file diff --git a/docs/projects/milky-monster/code.md b/docs/projects/milky-monster/code.md index 9aa0775c..6c59c0e4 100644 --- a/docs/projects/milky-monster/code.md +++ b/docs/projects/milky-monster/code.md @@ -77,7 +77,7 @@ basic.forever(() => { Your Milky Monster is ready! https://youtu.be/egl3fNAYylk - +
## ~button /projects/milky-monster/connect NEXT: Connect ## ~ \ No newline at end of file