integrate pxt-microbit changes

This commit is contained in:
Peli de Halleux 2016-10-10 14:43:33 -07:00
commit 3911c6522d
49 changed files with 719 additions and 476 deletions

View File

@ -13,10 +13,13 @@ export function deployCoreAsync(res: ts.pxtc.CompileResult) {
return getBitDrivesAsync()
.then(drives => {
if (drives.length == 0) {
console.log("cannot find any drives to deploy to")
} else {
console.log(`copy ${ts.pxtc.BINARY_HEX} to ` + drives.join(", "))
let msg = "cannot find any drives to deploy to";
console.log(msg);
return Promise.reject(new Error(msg));
}
console.log(`copy ${ts.pxtc.BINARY_HEX} to ` + drives.join(", "))
return Promise.map(drives, d =>
writeFileAsync(d + ts.pxtc.BINARY_HEX, res.outfiles[ts.pxtc.BINARY_HEX])
.then(() => {

View File

@ -1,13 +1,6 @@
<script type="text/javascript">
var appInsights=window.appInsights||function(config){
function r(config){t[config]=function(){var i=arguments;t.queue.push(function(){t[config].apply(t,i)})}}var t={config:config},u=document,e=window,o="script",s=u.createElement(o),i,f;for(s.src=config.url||"//az416426.vo.msecnd.net/scripts/a/ai.0.js",u.getElementsByTagName(o)[0].parentNode.appendChild(s),t.cookie=u.cookie,t.queue=[],i=["Event","Exception","Metric","PageView","Trace"];i.length;)r("track"+i.pop());return r("setAuthenticatedUserContext"),r("clearAuthenticatedUserContext"),config.disableExceptionTracking||(i="onerror",r("_"+i),f=e[i],e[i]=function(config,r,u,e,o){var s=f&&f(config,r,u,e,o);return s!==!0&&t["_"+i](config,r,u,e,o),s}),t
}({
instrumentationKey:"e9ae05ca-350b-427a-9775-3ba3f6efabce"
});window.appInsights=appInsights;
</script>
<script type="text/javascript">
(function(e,b){if(!b.__SV){var a,f,i,g;window.mixpanel=b;b._i=[];b.init=function(a,e,d){function f(b,h){var a=h.split(".");2==a.length&&(b=b[a[0]],h=a[1]);b[h]=function(){b.push([h].concat(Array.prototype.slice.call(arguments,0)))}}var c=b;"undefined"!==typeof d?c=b[d]=[]:d="mixpanel";c.people=c.people||[];c.toString=function(b){var a="mixpanel";"mixpanel"!==d&&(a+="."+d);b||(a+=" (stub)");return a};c.people.toString=function(){return c.toString(1)+".people (stub)"};i="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config reset people.set people.set_once people.increment people.append people.union people.track_charge people.clear_charges people.delete_user".split(" ");
for(g=0;g<i.length;g++)f(c,i[g]);b._i.push([a,e,d])};b.__SV=1.2;a=e.createElement("script");a.type="text/javascript";a.async=!0;a.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?MIXPANEL_CUSTOM_LIB_URL:"file:"===e.location.protocol&&"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js".match(/^\/\//)?"https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js":"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";f=e.getElementsByTagName("script")[0];f.parentNode.insertBefore(a,f)}})(document,window.mixpanel||[]);
mixpanel.init("762fef19c053a0ea4cec43d2fecae76e");
mixpanel.init("762fef19c053a0ea4cec43d2fecae76e", { disable_persistence: true });
if (pxtConfig) mixpanel.register({ target: pxtConfig.targetId, version: pxtConfig.targetVersion });
</script>

View File

@ -1,13 +1,6 @@
<script type="text/javascript">
var appInsights=window.appInsights||function(config){
function r(config){t[config]=function(){var i=arguments;t.queue.push(function(){t[config].apply(t,i)})}}var t={config:config},u=document,e=window,o="script",s=u.createElement(o),i,f;for(s.src=config.url||"//az416426.vo.msecnd.net/scripts/a/ai.0.js",u.getElementsByTagName(o)[0].parentNode.appendChild(s),t.cookie=u.cookie,t.queue=[],i=["Event","Exception","Metric","PageView","Trace"];i.length;)r("track"+i.pop());return r("setAuthenticatedUserContext"),r("clearAuthenticatedUserContext"),config.disableExceptionTracking||(i="onerror",r("_"+i),f=e[i],e[i]=function(config,r,u,e,o){var s=f&&f(config,r,u,e,o);return s!==!0&&t["_"+i](config,r,u,e,o),s}),t
}({
instrumentationKey:"e9ae05ca-350b-427a-9775-3ba3f6efabce"
});window.appInsights=appInsights;
</script>
<script type="text/javascript">
(function(e,b){if(!b.__SV){var a,f,i,g;window.mixpanel=b;b._i=[];b.init=function(a,e,d){function f(b,h){var a=h.split(".");2==a.length&&(b=b[a[0]],h=a[1]);b[h]=function(){b.push([h].concat(Array.prototype.slice.call(arguments,0)))}}var c=b;"undefined"!==typeof d?c=b[d]=[]:d="mixpanel";c.people=c.people||[];c.toString=function(b){var a="mixpanel";"mixpanel"!==d&&(a+="."+d);b||(a+=" (stub)");return a};c.people.toString=function(){return c.toString(1)+".people (stub)"};i="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config reset people.set people.set_once people.increment people.append people.union people.track_charge people.clear_charges people.delete_user".split(" ");
for(g=0;g<i.length;g++)f(c,i[g]);b._i.push([a,e,d])};b.__SV=1.2;a=e.createElement("script");a.type="text/javascript";a.async=!0;a.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?MIXPANEL_CUSTOM_LIB_URL:"file:"===e.location.protocol&&"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js".match(/^\/\//)?"https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js":"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";f=e.getElementsByTagName("script")[0];f.parentNode.insertBefore(a,f)}})(document,window.mixpanel||[]);
mixpanel.init("762fef19c053a0ea4cec43d2fecae76e");
mixpanel.init("762fef19c053a0ea4cec43d2fecae76e", { disable_persistence: true });
if (pxtConfig) mixpanel.register({ target: pxtConfig.targetId, version: pxtConfig.targetVersion });
</script>

View File

@ -13,14 +13,8 @@ Music
## Prior learning/place of lesson in scheme of work
Learn how to convert your BBC micro:bit into a music player using pins P0 and GND, earphones (or speakers), as well as crocodile clips (or spring clips). We will be learning how to code musical notes using simple commands such as play, keys, and notes.
## What the teacher needs to know / QuickStart Computing Glossary
* Hardware: The physical systems and components of digital devices; see also software.
* Programmable toys: Robots designed for children to use, accepting input, storing short sequences of simple instructions and moving according to this stored program.
* Program: A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output.
* Simulation: Using a computer to model the state and behaviour of real-world (or imaginary) systems, including physical or social systems; an integral part of most computer games.
Learn how to convert your BBC micro:bit into a music player using pins P0 and GND, earphones (or speakers), as well as crocodile clips (or spring clips).
We will be learning how to code musical notes using simple commands such as play, keys, and notes.
## Objectives

View File

@ -1,7 +1,5 @@
# hero
make a game to test hand-eye coordination.
Make a game to test hand-eye coordination
* [activity](/lessons/hero/activity)

View File

@ -2,6 +2,9 @@
Here are some cool projects that you can build with your micro:bit!
## Games
Fun games to build with your micro:bit.
```codecard
[{
@ -20,18 +23,42 @@ Here are some cool projects that you can build with your micro:bit!
"name": "Rock Paper Scissors",
"url":"/projects/rock-paper-scissors",
"imageUrl":"/static/mb/projects/a4-motion.png"
},{
"name": "Compass",
"url":"/projects/compass",
"imageUrl":"/static/mb/projects/a5-compass.png"
},{
}]
```
## Maker, Arts, Fashion
```codecard
[{
"name": "Hack your headphones",
"url":"/projects/hack-your-headphones",
"imageUrl":"/static/mb/projects/a6-music.png"
},{
}, {
"name": "Banana keyboard",
"url":"/projects/banana-keyboard",
"imageUrl":"/static/mb/projects/a7-conductive.png"
}, {
"name": "Guitar",
"url":"/projects/guitar",
"imageUrl":"/static/mb/projects/guitar.png"
}, {
"name": "Watch",
"url":"/projects/the-watch",
"imageUrl":"/static/mb/projects/a10-watch.png"
}, {
"name": "Timing gates",
"url":"/projects/timing-gates",
"imageUrl":"/static/mb/projects/timing-gates.jpg"
}]
```
## More
```codecard
[{
"name": "Compass",
"url":"/projects/compass",
"imageUrl":"/static/mb/projects/a5-compass.png"
},{
"name": "Telegraph",
"url":"/projects/telegraph",
@ -40,13 +67,9 @@ Here are some cool projects that you can build with your micro:bit!
"name": "Radio",
"url":"/projects/radio",
"imageUrl":"/static/mb/projects/a9-radio.png"
},{
"name": "Watch",
"url":"/projects/the-watch",
"imageUrl":"/static/mb/projects/a10-watch.png"
}]
```
### See Also
[Flashing Heart](/projects/flashing-heart), [Smiley Buttons](/projects/smiley-buttons), [Love Meter](/projects/love-meter), [Rock Paper Scissors](/projects/rock-paper-scissors), [Compass](/projects/compass), [Hack your headphones](/projects/hack-your-headphones), [Banana keyboard](/projects/banana-keyboard), [Telegraph](/projects/telegraph), [Radio](/projects/radio), [Watch](/projects/the-watch)
[Flashing Heart](/projects/flashing-heart), [Smiley Buttons](/projects/smiley-buttons), [Love Meter](/projects/love-meter), [Rock Paper Scissors](/projects/rock-paper-scissors), [Compass](/projects/compass), [Hack your headphones](/projects/hack-your-headphones), [Banana keyboard](/projects/banana-keyboard), [Telegraph](/projects/telegraph), [Radio](/projects/radio), [Guitar](/projects/guitar), [Watch](/projects/the-watch)

View File

@ -1,12 +1,16 @@
# banana keyboard activity
# banana keyboard
build a banana keyboard
### @description A beginner maker activity, building a piano from bananas.
# micro:bit banana keyboard
### ~avatar
Build your own micro:bit piano using bananas!
### ~
![](/static/mb/lessons/banana-keyboard-0.png)
In this project, you will build your own music player micro:bit banana keyboard from household fruit. Project duration: 15 minutes.
## Duration: ~20 minutes.
## Materials
@ -15,86 +19,11 @@ In this project, you will build your own music player micro:bit banana keyboard
* Orange
* Crocodile clips
## Steps
## Activities
### Step 1
![](/static/mb/lessons/banana-keyboard-1.png)
Using the 1st crocodile clip, connect the end of the crocodile clip onto GND pin on the micro:bit.
### Step 2
![](/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 micro:bit.
### Step 3
![](/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.
### Step 4
![](/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.
### Step 5
![](/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.
### Step 6
![](/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.
### Step 7
![](/static/mb/lessons/banana-keyboard-10.png)
Using the 4th crocodile clip, connect the end of the crocodile clip onto pin 1 on the micro:bit.
### Step 8
![](/static/mb/lessons/banana-keyboard-11.png)
Using the 4th crocodile clip, connect the unattached end of the crocodile clip onto the banana.
### Step 9
![](/static/mb/lessons/banana-keyboard-12.png)
Your banana keyboard is ready!
### Step 10
Connect your micro:bit to your computer using your USB cable and run this script:
```blocks
let sound = music.noteFrequency(Note.C);
input.onPinPressed(TouchPin.P1, () => {
for (let i = 0; i < 5; i++) {
sound = sound + 25;
music.playTone(sound, music.beat(BeatFraction.Sixteenth));
}
});
```
Tap your banana instrument to play sound against... the fruit!
### ~avatar boothing
Excellent, you're ready to continue with the [challenges](/projects/banana-keyboard-challenges)!
* [Making the keyboard](/projects/banana-keyboard/making)
* [Beat box](/projects/banana-keyboard/beat-box)
### ~button /projects/banana-keyboard/making
Let's get started!
### ~

View File

@ -1,10 +1,4 @@
# banana keyboard blocks challenges
control images with variables.
## Before we get started
Control images with variables.
# banana keyboard - beat box
Have you ever tried to making beat box sounds? Let's try making a beatbox with code!
@ -35,7 +29,7 @@ input.onPinPressed(TouchPin.P1, () => {
```
* click *run* to see if the code works as expected.
* click *Download* to see if the code works as expected.
@ -57,8 +51,4 @@ input.onPinPressed(TouchPin.P2, () => {
})
```
* click *run* to see if the code works as expected.
### ~button /projects/telegraph
NEXT: Telegraph
### ~
* click *Download* to see if the code works as expected.

View File

@ -0,0 +1,85 @@
# banana keyboard - making
## Materials
* micro:bit, battery holder and 2 AAA batteries
* Bananas
* Orange
* Crocodile clips
## Steps
### Step 1
![](/static/mb/lessons/banana-keyboard-1.png)
Using the 1st crocodile clip, connect the end of the crocodile clip onto GND pin on the micro:bit.
### Step 2
![](/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 micro:bit.
### Step 3
![](/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.
### Step 4
![](/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.
### Step 5
![](/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.
### Step 6
![](/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.
### Step 7
![](/static/mb/lessons/banana-keyboard-10.png)
Using the 4th crocodile clip, connect the end of the crocodile clip onto pin 1 on the micro:bit.
### Step 8
![](/static/mb/lessons/banana-keyboard-11.png)
Using the 4th crocodile clip, connect the unattached end of the crocodile clip onto the banana.
### Step 9
![](/static/mb/lessons/banana-keyboard-12.png)
Your banana keyboard is ready!
### Step 10
Connect your micro:bit to your computer using your USB cable and run this script:
```blocks
input.onPinPressed(TouchPin.P1, () => {
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quarter));
});
```
Tap your banana instrument to play sound against... the fruit!
### ~button /projects/banana-keyboard/beat-box
NEXT: beat box
### ~

View File

@ -103,7 +103,3 @@ basic.forever(() => {
}
});
```
### ~button /projects/hack-your-headphones
NEXT: Hack Your Headphones
### ~

View File

@ -113,7 +113,3 @@ basic.clearScreen();
basic.pause(500);
})
```
### ~button /projects/smiley-buttons
NEXT: Smiley Buttons
### ~

View File

@ -1,10 +1,12 @@
# Guitar
![guitar icon](/static/mb/projects/guitar.png)
### @description A beginner-intermediate maker activity, building a guitar with the micro:bit
### ~avatar avatar
Make a micro:bit guitar with this guided tutorial!
Make a micro:bit guitar with this guided tutorial!
### ~
*playing micro:bit guitar*
@ -12,19 +14,21 @@ https://youtu.be/GYmdTFvxz80
## Duration
5 Activities, approx 30-45 min each based on familiarity with the coding concepts
5 Activities, approx 30-45 min each based on familiarity with the coding concepts
## Materials
* Cardboard large pieces (recycle!)
* Tape (masking, duct Tape, and/or packing tape)
* Tape (masking, duct tape, and/or packing tape)
* Markers and/or paint
* Aluminum Foil
* Scissors that can cut cardboard
* Scissors that can cut cardboard
* 1 micro:bit, battery holder and 2 AAA batteries
* 4-5 Crocodile clips
* Headphones
## Activities
* [Making the Guitar Body](/projects/guitar/making)
* [Buttons, Display & Sound](/projects/guitar/displaybuttons)
* [Light Sensor Tone control](/projects/guitar/lightsensor)
@ -32,5 +36,7 @@ https://youtu.be/GYmdTFvxz80
* [Pin Press Switch](/projects/guitar/pinpress)
### ~button /projects/guitar/making
Let's get started!
### ~

View File

@ -5,7 +5,6 @@
### ~avatar avatar
Use the Accelerometer to control guitar tempo
* Duration: 30 - 45 minutes
* Concepts:
* Gravity
* Acceleration
@ -18,9 +17,11 @@ Use the Accelerometer to control guitar tempo
### ~
## Duration: 30 - 45 minutes
*accelerometer controlled tempo*
https://youtu.be/h_gPkBaVkoo
TODO: add sound to video
https://youtu.be/kA0HpqCWsjs
## Blocks
```cards

View File

@ -2,7 +2,7 @@
### @description micro:bit guitar: using buttons with display and sound
### ~avatar avatar
Use Button Events to control LED Display and play Sound
Use Button Events to control LED Display and play Sound
* **Concepts:**
* Events
* Tone/Note
@ -42,8 +42,8 @@ music.rest(music.beat(BeatFraction.Whole))
music.beat(BeatFraction.Quarter)
```
## Step 1: Make a Smiley
Open [codethemicrobit.com](https://codethemicrobit.com) in your web browser
## Step 1: Make a Smiley
Open [codethemicrobit.com](https://codethemicrobit.com) in your web browser
```blocks
basic.showLeds(`
. # . # .
@ -53,14 +53,14 @@ Open [codethemicrobit.com](https://codethemicrobit.com) in your web browser
. # # # .
`);
```
From **Basics**, drag a **show LEDs** block into the coding area
* Create a face with LEDs
From **Basics**, drag a **show LEDs** block into the coding area
* Create a face with LEDs
![micro:bit USB connection](/static/mb/projects/guitar/connectmicrobit.jpg)
Connect your micro:bit to your computer via USB and click **`Download`**.
Follow the instructions to move the code to your micro:bit.
![micro:bit USB connection](/static/mb/projects/guitar/connectmicrobit.jpg)
Connect your micro:bit to your computer via USB and click **`Download`**.
Follow the instructions to move the code to your micro:bit.
## Step 2: Add Smiley LED Button Events
## Step 2: Add Smiley LED Button Events
```blocks
input.onButtonPressed(Button.A, () => {
basic.showLeds(`
@ -82,36 +82,36 @@ input.onButtonPressed(Button.B, () => {
})
```
From **Input**, drag an **on button 'A' pressed** block into the coding area
From **Input**, drag an **on button 'A' pressed** block into the coding area
* Snap the LED face into the block
* Snap the LED face into the block
* Create a 'B' button block with a different LED face
* Create a 'B' button block with a different LED face
* Download the code to your micro:bit and try the A & B buttons
* Download the code to your micro:bit and try the A & B buttons
## Step 3: Add Headphone Speakers using Crocodile clips
![crocodile clips attached to pins 0 and GND](/static/mb/projects/guitar/crocclipintoboard.jpg)
![crocodile clips attached to pins 0 and GND](/static/mb/projects/guitar/crocclipintoboard.jpg)
![crocodile clips attached to headphone jack](/static/mb/projects/guitar/jacktocrocs.jpg)
Connect **GND** to the **base of the headphone jack** using a second crocodile clip (usually black)
![crocodile clips attached to headphone jack](/static/mb/projects/guitar/jacktocrocs.jpg)
Connect **GND** to the **base of the headphone jack** using a second crocodile clip (usually black)
Connect **pin 0** to the **tip of the headphone jack** with a crocodile clip
Connect **pin 0** to the **tip of the headphone jack** with a crocodile clip
*attaching batteries and micro:bit*
https://youtu.be/zwRTmpKIaVU
Attach the micro:bit & battery-pack to the guitar body
*attaching batteries and micro:bit*
https://youtu.be/zwRTmpKIaVU
Attach the micro:bit & battery-pack to the guitar body
*connecting headphone speaker*
https://youtu.be/ewyEW_U5G9M
Connect the headphones with crocodile clips
*connecting headphone speaker*
https://youtu.be/ewyEW_U5G9M
Connect the headphones with crocodile clips
### ~hint
## The micro:bit can play music
The **play tone** block allows a range letter note tones from **C** to **B5**.
The **play tone** block allows a range letter note tones from **C** to **B5**.
Songs are played using sequences notes. Like the beginning of a birthday song (C, C, D, C, F, E).
```blocks
input.onButtonPressed(Button.A, () => {
@ -152,20 +152,20 @@ input.onButtonPressed(Button.B, () => {
`)
music.playTone(Note.G, music.beat(BeatFraction.Whole))
})
```
From **Music**, drag **play tone *C* for *1* beat** block under the **show leds** in **Button A Pressed**
```
From **Music**, drag **play tone *C* for *1* beat** block under the **show leds** in **Button A Pressed**
* modify **tone** by choosing a note (*letter*) and experiment with high and low pitches
* set **beat** to 1
**Repeat** for **Button B** event
**Download the code** to the micro:bit
* modify **tone** by choosing a note (*letter*) and experiment with high and low pitches
* set **beat** to 1
**Repeat** for **Button B** event
**Download the code** to the micro:bit
**Try the A & B buttons** with headphones and power connected
## Congratulations on completing the basic guitar!
**Challenge:** Create Samples of longer music to play for each button instead of the single tone
## Congratulations on completing the basic guitar!
**Challenge:** Create samples of longer music to play for each button instead of the single tone
* *Tip*: Search for "ABC music notation" or "Easy Music Notes" + the name of a song
## Extra

View File

@ -4,28 +4,27 @@
### ~avatar avatar
Use the Light Sensor to control guitar Tone
* **Duration:** 30 - 45 minutes
Use the Light Sensor to the control tone for this [Theremin](https://en.wikipedia.org/wiki/Theremin) inspired guitar
* **Concepts:**
* Inputs
* Light Intensity
* Tone/Frequency
* Ratio Mapping
* Forever Loop
* Math (multiplication) with code properties
* **Resources:**
* This guitar is inspired by the [Theremin](https://en.wikipedia.org/wiki/Theremin)
* Math (multiplication) with code properties
### ~
### ~
## Duration: 30 - 45 minutes
*playing tones with light sensor*
*playing tones with light sensor*
https://youtu.be/2cKg9pokVC4
## The micro:bit LEDs Light Sensors
## The micro:bit LEDs Light Sensors
- the micro:bit can detect external light level intensity reaching the LEDs
- the micro:bit can detect external light level intensity reaching the LEDs
- the light level block reports a reading of values 0 (*dark*) to 255 (*bright*)
- a **Forever Loop** is required to continually use measure the current light level to control the tone
- a **Forever Loop** is required to continually measure the current light level and control the tone
## Forever Loop
@ -47,70 +46,70 @@ basic.forever(() => {
})
```
**Build the blocks**
* From **Basic** drag a **forever loop** block into the coding area
* From **Led** drag a **plot bar graph** block into the **forever loop**
* From **Input** drag a **light level** block into **plot bar graph *of***
**Set the *plot bar graph* value *up to* = *255* **
* From **Basic** drag a **forever loop** block into the coding area
* From **Led** drag a **plot bar graph** block into the **forever loop**
* From **Input** drag a **light level** block into **plot bar graph *of***
## Step 2: Test the light required to move the bar graph height
**Set the *plot bar graph* value *up to* = *255* **
*graphing light input*
https://youtu.be/pqU7bTcfQ_s
Experiment to see the effect on graph height when the **plot bar graph** value ***up to*** is changed
## Step 2: Test the light required to move the bar graph height
**255 is the maximum light input reading**, try numbers smaller than 255
**Find a value** that allows the graph to show 1 - 5 bars
*graphing light input*
https://youtu.be/pqU7bTcfQ_s
Experiment to see the effect on graph height when the **plot bar graph** value ***up to*** is changed
**255 is the maximum light input reading**, try numbers smaller than 255
**Find a value** that allows the graph to show 1 - 5 bars
### ~hint
### Frequency
**Frequency** measured in Hz which are cycles per second or vibrations per second
* A healthy human ear can detect frequencies in the range of 20Hz to 20,000Hz.
* The micro:bit + headphones reliably produce detectable output ~50Hz - 6,000Hz.
### Frequency
**Frequency** measured in Hz which are cycles per second or vibrations per second
* A healthy human ear can detect frequencies in the range of 20Hz to 20,000Hz.
* The micro:bit + headphones reliably produce detectable output ~50Hz - 6,000Hz.
**261Hz** represents a C note
```blocks
music.playTone(261, music.beat(BeatFraction.Half))
```
**play tone** blocks can specify a specific numeric **Frequency**
by replacing the letter note 261Hz represents a **C** note with a **number** block
**play tone** blocks can specify a numeric **Frequency**
by replacing the letter **C** note with a **number** block that has the value it represents
```blocks
music.playTone(261, music.beat(BeatFraction.Half))
```
### ~
### ~
## Step 3: Multiply Frequency using Math blocks
```blocks
input.onButtonPressed(Button.A, () => {
music.playTone(261 * 2, music.beat(BeatFraction.Half))
})
```
create a **play tone** block using a **Math** section, **multiplication** block to set *tone*
```
Create a **play tone** block using a **Math** section, **multiplication** block to set *tone*
### Next
**Add** a **B** button block that multiplies the **261** tone by a number other than 2 to set tone
**Download the code to the micro:bit**
### Next
**Add** a **B** button block that multiplies the **261** tone by a number other than 2 to set tone
**Download the code to the micro:bit**
**Test the sound for multiples of the 261Hz *C* frequency**
**Test the sound for multiples of the 261Hz *C* frequency**
## Step 4: Control the Frequency with the light input
```blocks
basic.forever(() => {
music.playTone(input.lightLevel() * 25, music.beat(BeatFraction.Quarter))
})
```
**Create a *forever loop* containing a *play tone* block**
**Set *tone*, using *Math* multiplication block that multiplies *light level* input by 25**
or experiment with multipliers larger and smaller than 25
**Test light tone control on the guitar**
Cover the LEDs with your hand to vary light detected to control the tone
**Create a *forever loop* containing a *play tone* block**
**Set *tone*, using *Math* multiplication block that multiplies *light level* input by 25**
or experiment with multipliers larger and smaller than 25
**Test light tone control on the guitar**
Cover the LEDs with your hand to vary light detected to control the tone
## Good work, this guitar is sounding good!
**Challenge:** Create a variable for the light level multiplier that you can change using buttons (optional)
**Challenge:** Create a variable for the light level multiplier that you can change using buttons (optional)
### ~button /projects/guitar/accelerometer
NEXT: Accelerometer Beat control
### ~button /projects/guitar/accelerometer
NEXT: Accelerometer Beat control
### ~

View File

@ -1,5 +1,5 @@
# Making the Guitar Body
### @description Maker Project for Guitar Body for micro:bit
### @description Maker Project for Guitar Body for micro:bit
### ~avatar avatar
@ -11,9 +11,9 @@ Make the Guitar Body for your micro:bit Guitar
## Materials
* Cardboard large pieces (recycle!)
* Tape (masking, duct Tape, and/or packing tape)
* Scissors that can cut cardboard
* Markers and/or paint
* Tape (masking, duct tape, and/or packing tape)
* Scissors that can cut cardboard
* Markers and/or paint
![Materials: cardboard, tape, scissors, markers](/static/mb/projects/guitar/materials.jpg)
@ -28,7 +28,7 @@ the shape of your guitar
### ~hint
* Avoid small details that are difficult to cut into cardboard
* Unfolding a box gives longer pieces of cardboard, and creases can be reinforced
* Unfolding a box gives longer pieces of cardboard and creases can be reinforced
### ~
@ -39,21 +39,21 @@ https://youtu.be/aUQkrFoEank
## Step 3: Personalize the Guitar
Create unique styling using tape, markers, paint and other available materials (*calling all artist!*)
Create unique styles using tape, markers, paint and other available materials (*calling all artists!*)
*decorating the guitar*
https://youtu.be/zNAZTJeSxY8
Everyone can come up with a unique design!
Everyone can come up with a unique design!
![guitar design samples](/static/mb/projects/guitar/otherdesigns.jpg)
## Extra!
*strengthening the guitar*
*strengthening the guitar*
https://youtu.be/q0GkQdJmxjE
Strengthen the guitar next with an angled cardboard strip (*optional*).
Strengthen the guitar next with an angled cardboard strip (*optional*).
### ~button /projects/guitar/displaybuttons
NEXT: Buttons, Display and Sound
### ~

View File

@ -4,17 +4,20 @@
### ~avatar avatar
Use pin press to switch guitar play on/off
* **Duration:** approximately 45 minutes
* **Materials:**
* 2-3 Crocodile clips
* Concepts:
* Circuit
* Conductor
* Variable/Global-Variable
* Conditional: **`if`**, **`else`**
* Circuit
* Conductor
* Variable/Global-Variable
* Conditional: **`if`**, **`else`**
* Boolean: **`True`/`False`**
### ~
## Duration: approximately 45 minutes
## Materials:
2-3 Crocodile clips
## Blocks
```cards
@ -28,16 +31,16 @@ input.onPinPressed(TouchPin.P1, () => {})
### ~hint
## Circuits & Switches
* **Circuits** need a power supply (battery), a resister (like a LED) & a conductor (metal, water, hand)
* **Switches** turn electric power on by closing (completing) a circuit with a conductor so power can flow
* **Circuits** need a power supply (battery), a resister (like a LED) & a conductor (metal, water, hand)
* **Switches** turn electric power on by closing (completing) a circuit with a conductor so power can flow
**Metal foil and wires make excellent conductors**
**Metal foil and wires make excellent conductors**
**In this activity we use YOU to conduct electricity**
**to close the circuit that switches the guitar ON and OFF!**
**In this activity we use YOU to conduct electricity**
**to close the circuit that switches the guitar ON and OFF!**
### ~
## Step 1: Pin Press Test
## Step 1: Pin Press Test
```blocks
input.onPinPressed(TouchPin.P0, () => {
@ -49,34 +52,34 @@ input.onPinPressed(TouchPin.P1, () => {
input.onPinPressed(TouchPin.P2, () => {
basic.showNumber(2)
})
```
**Create the pin-press code**
```
**Create the pin-press code**
**Download the code** on the micro:bit
**Download the code** on the micro:bit
https://youtu.be/PAIU-vHqyGU
https://youtu.be/PAIU-vHqyGU
**Hold the micro:bit touching The GND pin with one hand**
**with the other hand alternately touch the 0, 1 and 2 pins**
**Hold the micro:bit touching The GND pin with one hand**
**with the other hand alternately touch the 0, 1 and 2 pins**
### ~hint
**The electric signal traveled from pins, between your hands to `GND` and the micro:bit detected the electric signal!**
### ~
## Step 2: Installing conductive foil on the guitar
https://youtu.be/NX0ECcpXFes
**Add foil to the guitar body where it is easy to touch while playing**
**The electric signal traveled from pins, between your hands to `GND` and the micro:bit detected the electric signal!**
### ~
**Connect the foil to `GND` using a crocodile clip**
## Step 2: Installing conductive foil on the guitar
https://youtu.be/NX0ECcpXFes
**Add foil to the guitar body where it is easy to touch while playing**
https://youtu.be/YkymZGNmkrE
**Add foil to the guitar neck**
**Connect the foil to `pin 1` using a crocodile clip**
**Connect the foil to `GND` using a crocodile clip**
## Step 3: Add a switch to turn the guitar ON and OFF
**Using the `on` global variable we can switch the message on the micro:bit**
**between ON and OFF**
https://youtu.be/YkymZGNmkrE
**Add foil to the guitar neck**
**Connect the foil to `pin 1` using a crocodile clip**
## Step 3: Add a switch to turn the guitar ON and OFF
**Using the `on` global variable we can switch the message on the micro:bit**
**between ON and OFF**
```blocks
let on = false
basic.forever(() => {
@ -93,11 +96,11 @@ input.onPinPressed(TouchPin.P1, () => {
on = true
}
})
```
**Create the ON/OFF switch code**
```
**Create the ON/OFF switch code**
**Download the code on the micro:bit**
**Download the code on the micro:bit**
**Test by touching `P1` to toggle the LED message between ON and OFF**
*Final code*
@ -120,9 +123,9 @@ basic.forever(() => {
input.onPinPressed(TouchPin.P1, () => {
on = !on;
})
```
## Now Play!
**Turn the guitar ON and OFF with a pin press on the connected foil**
**touching both pieces of foil at the same time to connect the switches**
https://youtu.be/GYmdTFvxz80
```
## Now Play!
**Turn the guitar ON and OFF with a pin press on the connected foil by**
**touching both pieces of foil at the same time to connect the switches**
https://youtu.be/GYmdTFvxz80

View File

@ -1,12 +1,17 @@
# hack your headphones
Hack your headphones
### @description A beginner maker activity, building a piano from bananas.
# micro:bit music
### ~avatar
Build your own music player micro:bit from headphones.
### ~
![](/static/mb/lessons/hack-your-headphones-0.png)
In this project, you will build your own music player micro:bit from headphones. Project duration: 15 minutes.
## Duration: ~15 minutes.
## Materials
@ -14,48 +19,13 @@ In this project, you will build your own music player micro:bit from headphones.
* Headphones
* Crocodile clips
## Steps
## Activities
### Step 1
* [Connect your headphone](/projects/hack-your-headphone/making)
* [Play sounds!]()
![](/static/mb/lessons/banana-keyboard-1.png)
### ~button /projects/hack-your-headphones/making
Using the 1st crocodile clip, connect the end of the crocodile clip onto GND pin on the micro:bit.
### Step 2
![](/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 micro:bit.
### Step 3
![](/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. The base of your headphone jack is considered the ground so it is connected to the GND of the micro:bit.
### Step 4
![](/static/mb/lessons/banana-keyboard-5.png)
![](/static/mb/lessons/hack-your-headphones-1.png)
Using the 2nd crocodile clip, connect the second end of the crocodile clip onto the tip of the headphone jack. The tip of your headphone jack feeds into the right speaker on the headphone. You connect from the micro:bit pin 0 to the tip of the right side of your headphone. Use the tip of the headphone jack to play sounds.
### Step 5
![](/static/mb/lessons/hack-your-headphones-0.png)
You hacked your headphones!
### Step 6
Connect your micro:bit to your computer using your USB cable and program [light beatbox](/projects/hack-your-headphones-challenges) music on it. Press the reset button to restart your music player!
### ~avatar avatar
Excellent, you're ready to continue with the [challenges](/projects/hack-your-headphones-challenges)!
Let's get started!
### ~

View File

@ -0,0 +1,47 @@
# hack your headphones - making
### ~avatar avatar
Did you know you could attach your headhpones to the micro:bit to generate sounds?
### ~
### Step 1
![](/static/mb/lessons/banana-keyboard-1.png)
Using the 1st crocodile clip, connect the end of the crocodile clip onto GND pin on the micro:bit.
### Step 2
![](/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 micro:bit.
### Step 3
![](/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. The base of your headphone jack is considered the ground so it is connected to the GND of the micro:bit.
### Step 4
![](/static/mb/lessons/banana-keyboard-5.png)
![](/static/mb/lessons/hack-your-headphones-1.png)
Using the 2nd crocodile clip, connect the second end of the crocodile clip onto the tip of the headphone jack. The tip of your headphone jack feeds into the right speaker on the headphone. You connect from the micro:bit pin 0 to the tip of the right side of your headphone. Use the tip of the headphone jack to play sounds.
### Step 5
![](/static/mb/lessons/hack-your-headphones-0.png)
You hacked your headphones!
### ~button /projects/hack-your-headphones/music-of-light
NEXT: music of light
### ~

View File

@ -1,6 +1,4 @@
# hack your headphones challenges
Control sound with the light level.
# hack your headphones - music of light
### ~avatar avatar
@ -70,7 +68,3 @@ input.onButtonPressed(Button.A, () => {
```
* click **Download** and run your code on the micro:bit.
### ~button /projects/banana-keyboard
NEXT: Banana Keyboard
### ~

View File

@ -48,7 +48,3 @@ input.onPinPressed(TouchPin.P2, () => {
`);
});
```
### ~button /projects/rock-paper-scissors
NEXT: Rock Paper Scissors
### ~

View File

@ -89,10 +89,6 @@ Have fun reviewing your simulation and analyze the acceleration by chart the Exc
* Review and analyze the actual micro:bit device acceleration data on Excel
* Display acceleration with y or z using plot bar graph by changing acceleration from "x" to "y" or "z"
### ~button /projects/the-watch
NEXT: The Watch
### ~
```package
microbit-radio
```

View File

@ -236,6 +236,3 @@ input.onButtonPressed(Button.B, () => {
How else can you make your game better?
Ever hear of [Rock Paper Scissors Spock Lizard](http://www.samkass.com/theories/RPSSL.html)?
### ~button /projects/compass
NEXT: Compass
### ~

View File

@ -67,7 +67,3 @@ input.onButtonPressed(Button.B, () => {
. # # # .`);
});
```
### ~button /projects/love-meter
NEXT: Love Meter
### ~

View File

@ -1,75 +1,25 @@
# telegraph activity
Build a telgraph.
# micro:bit telegraph
![](/static/mb/lessons/telegraph-0.png)
In this project, you will build your telegraph between micro:bits. Project duration: 15 minutes.
### ~avatar
Build a telegraph between two micro:bits to communicate with your friends!
### ~
## Duration: ~30 minutes
## Materials
* micro:bit, battery holder and 2 AAA batteries
* Crocodile clips
## Steps
## Activities
### Step 1
![](/static/mb/lessons/banana-keyboard-1.png)
Using the 1st crocodile clip, connect the end of the crocodile clip onto GND pin on the micro:bit.
### Step 2
![](/static/mb/lessons/ornament-chain-2.png)
Using the 2nd crocodile clip, connect the end of the crocodile clip onto the 3V pin on the micro:bit.
### Step 3
![](/static/mb/lessons/ornament-chain-3.png)
Using the 3rd crocodile clip, connect the end of the crocodile clip onto pin 1 of the micro:bit.
### Step 4
![](/static/mb/lessons/ornament-chain-4.png)
Using the 4th crocodile clip, connect the end of the crocodile clip onto pin 2 of the micro:bit.
### Step 5
![](/static/mb/lessons/ornament-chain-5.png)
Using the 1st crocodile clip, connect the unattached end of the crocodile clip onto the GND on the 2nd micro:bit.
### Step 6
![](/static/mb/lessons/ornament-chain-6.png)
Using the 2nd crocodile clip, connect the unattached end of the crocodile clip onto the 3V pin on the 2nd micro:bit.
### Step 7
![](/static/mb/lessons/ornament-chain-7.png)
Using the 3rd crocodile clip, connect the unattached end of the crocodile clip onto pin 2 of the 2nd micro:bit.
### Step 8
![](/static/mb/lessons/ornament-chain-8.png)
Using the 4th crocodile clip, connect the unattached end of the crocodile clip onto pin 1 of the 2nd micro:bit
### Step 9
![](/static/mb/lessons/telegraph-0.png)
### ~avatar avatar
Excellent, you're ready to continue with the [challenges](/projects/telegraph-challenges)!
* [Making the circuit](/projects/telegraph/making)
* [Manual telegraph](/projects/telegraph/manual-telegraph)
### ~button /projects/telegraph/making
Let's get started!
### ~

View File

@ -0,0 +1,75 @@
# telegraph - making
### ~avatar
Let's build a telegraph between two micro:bits.
### ~
![](/static/mb/lessons/telegraph-0.png)
## Materials
* micro:bit, battery holder and 2 AAA batteries
* Crocodile clips
## Steps
### Step 1
![](/static/mb/lessons/banana-keyboard-1.png)
Using the 1st crocodile clip, connect the end of the crocodile clip onto GND pin on the micro:bit.
### Step 2
![](/static/mb/lessons/ornament-chain-2.png)
Using the 2nd crocodile clip, connect the end of the crocodile clip onto the 3V pin on the micro:bit.
### Step 3
![](/static/mb/lessons/ornament-chain-3.png)
Using the 3rd crocodile clip, connect the end of the crocodile clip onto pin 1 of the micro:bit.
### Step 4
![](/static/mb/lessons/ornament-chain-4.png)
Using the 4th crocodile clip, connect the end of the crocodile clip onto pin 2 of the micro:bit.
### Step 5
![](/static/mb/lessons/ornament-chain-5.png)
Using the 1st crocodile clip, connect the unattached end of the crocodile clip onto the GND on the 2nd micro:bit.
### Step 6
![](/static/mb/lessons/ornament-chain-6.png)
Using the 2nd crocodile clip, connect the unattached end of the crocodile clip onto the 3V pin on the 2nd micro:bit.
### Step 7
![](/static/mb/lessons/ornament-chain-7.png)
Using the 3rd crocodile clip, connect the unattached end of the crocodile clip onto pin 2 of the 2nd micro:bit.
### Step 8
![](/static/mb/lessons/ornament-chain-8.png)
Using the 4th crocodile clip, connect the unattached end of the crocodile clip onto pin 1 of the 2nd micro:bit
### Step 9
![](/static/mb/lessons/telegraph-0.png)
### ~button /projects/telegraph/manual-telegraph
NEXT: manual telegraph
### ~

View File

@ -1,18 +1,10 @@
# telegraph activity
# telegraph - manual telegraph
Build a telegraph.
# micro:bit telegraph
Have you ever tried to communicate through a telegraph? Let's try coding a "Telegraph" on two BBC micro:bits !
Complete the following [tutorial](/projects/telegraph), your hack should look like this:
![](/static/mb/lessons/telegraph-0.png)
Let's build the code that will send a impulse while the user presses ``A``.
### Step 1
We now need to digitally write to the specified pin (P0) as digital. Let's start by adding the code in the pin drawer that includes 'digital write (0,1) to pin P0'.. Then insert 1 for digital write.
We now need to digitally write to pin ``P0`` as **high** (1).
```blocks
pins.digitalWritePin(DigitalPin.P0, 1)
@ -21,7 +13,8 @@ pins.digitalWritePin(DigitalPin.P0, 1)
### Step 2
We want to add a block to turn on an LED in the middle area of the LED display using plot x, y. So insert the appropriate LED plot x, y.
We want to add a block to turn on an LED in the middle area of the LED display using plot x, y.
So insert the appropriate LED plot x, y.
```blocks
pins.digitalWritePin(DigitalPin.P0, 1)
@ -31,7 +24,8 @@ led.plot(2, 2)
### Step 3
We want to insert a condition that tells us when to turn on the LED. So insert the if block under logic drawer. Then add a condition that occurs if we do not turn on a LED with plot x, y. We also should plot an LED on the display if button A is pressed. Your code should appear as follows:
We want to insert a condition that tells us when to turn on the LED. So insert the if block under logic drawer.
Then add a condition that occurs if we do not turn on a LED with plot x, y. We also should plot an LED on the display if button A is pressed. Your code should appear as follows:
```blocks
if (input.buttonIsPressed(Button.A)) {
@ -45,7 +39,7 @@ if (input.buttonIsPressed(Button.A)) {
### Step 4
We want to write code if button A is NOT pressed. It is important to say that digital write is not on. We also want to turn off all LED lights on the LED screen
We want to write code if button A is NOT pressed. It is important to say that digital write is not on. We also want to turn off all the LED light.
```blocks
if (input.buttonIsPressed(Button.A)) {
@ -53,7 +47,7 @@ if (input.buttonIsPressed(Button.A)) {
led.plot(2, 2)
} else {
pins.digitalWritePin(DigitalPin.P0, 0)
basic.clearScreen()
led.unplot(2, 2)
}
```
@ -64,27 +58,24 @@ Let's add a forever loop so this code runs in the background forever. Modify you
```blocks
basic.forever(() => {
if (input.buttonIsPressed(Button.A)) {
pins.digitalWritePin(DigitalPin.P0, 1)
led.plot(2, 2)
} else {
pins.digitalWritePin(DigitalPin.P0, 0)
basic.clearScreen()
}
})
pins.digitalWritePin(DigitalPin.P0, 1)
led.plot(2, 2)
} else {
pins.digitalWritePin(DigitalPin.P0, 0)
led.unplot(2, 2)
})
```
### Step 6
We now need to digitally read to the specified pin (P1) as digital. Let's start by going to the pin drawer and adding digital read pin (0,1) and changing the pin to P1. Now we need to create a condition for digital read pin (0,1). So we go to the logic drawer and select the comparison operator. Then we want to set the comparison operator to 1 to turn on digital read on pin 1. We want to insert a condition that tells us if button A is pressed and we should turn on digital read on pin 1. So insert the if block under logic drawer. Then add a condition that occurs if digital read on P1 is on. Then we want to plot x, y at the x, y coordinates of 2,2. we also want to say that if digital read pin P1 is not on, we want to turn off all LED lights on the screen. Your code should appear as follows:
```blocks
if (pins.digitalReadPin(DigitalPin.P1) == 1) {
led.plot(2, 2);
led.plot(4, 4);
}
else {
basic.clearScreen();
led.unplot(4, 4);
}
basic.forever(() => {
if (input.buttonIsPressed(Button.A)) {
@ -108,7 +99,3 @@ Your telegraph is ready!
* Connect the first micro:bit to your computer using your USB cable and put the telegraph script on it.
* Connect the second micro:bit to your computer using your USB cable and run the telegraph script on it.
* The first person and second person take turns pressing button A to play the telegraph game!
### ~button /projects/radio
NEXT: Radio
### ~

View File

@ -0,0 +1,231 @@
# Timing gates
### ~avatar
This project explains the principles of timing gates using household materials.
### ~
## Timing gates
The two gates are connected to the micro:bit and can detect a car passing through.
![](/static/mb/projects/timing-gates/sketchgates.jpg "Sketch of the gates")
As the car passes through the gate ``0``, it sends an event to the micro:bit through the [on pin pressed](/reference/input/on-pin-pressed) block.
The micro:bit records the time in a variable ``t0``.
![](/static/mb/projects/timing-gates/sketchgate1.jpg "Sketch first gate")
As the car passes through the gate ``1``, it sends an event to the micro:bit through the [on pin pressed](/reference/input/on-pin-pressed) block.
The micro:bit records the time in a variable ``t1``.
![](/static/mb/projects/timing-gates/sketchgate2.jpg "Sketch first gate")
The rest is a bit of math and physics. The time taken to cross the gates is computed as the difference of ``t1 - t0``.
By dividing the distance between the gates by the duration, we get the speed of the car!
![](/static/mb/projects/timing-gates/sketchmath.jpg "Sketch math")
## Materials
* Carboard
* Aluminum fail
* Double-side tape (carpet tape)
* 4 crocodile clips
* A micro:bit board and USB cable
![](/static/mb/projects/timing-gates/materials.jpg "Materials")
## blocks
```cards
basic.showLeds(`
. . . . .
. . . . .
. . # . .
. . . . .
. . . . .
`)
input.onPinPressed(TouchPin.P0, () => {})
let t = 0
input.runningTime()
t - 1
control.eventTimestamp();
basic.showNumber(0)
```
## Building the gate
The sensor is made by tapping two strips of fail on the cardboard as close as possible.
Add two strips of double-sided tape on the cardboard. Remove the protective film.
![](/static/mb/projects/timing-gates/tape.jpg "Double sided tape")
Lay the Aluminum foil on the double-sided tape. Press firmly on the tape to get a good bonding of the foil.
![](/static/mb/projects/timing-gates/stickfoil.jpg "Foil sensor")
Strip the out foil around and between the tape strips. Make sure both foil strips don't touch each other.
![](/static/mb/projects/timing-gates/spreadfoil.jpg "Foil taped")
Connect a crocodile strip to each foil strip.
![](/static/mb/projects/timing-gates/connectsensor.jpg "Connecting sensor")
Connect the crocodile plugs to the ``GND`` and ``P0`` pins on the micro:bit.
![](/static/mb/projects/timing-gates/connectcrocs.jpg "Connecting the micro:bit")
The gate is ready to use! Your circuit should look like the picture below:
![](/static/mb/projects/timing-gates/sensordone.jpg "A single gate")
## Detecting the car with code
The micro:bit provides an event [on pin pressed](/reference/pins/on-pin-pressed)
that is raised when a circuit between ``GND`` and a pin is detected. The circuit conductor could be a wire or even your body!
We will attach a foil to the bottom of the car. When it passes over the gate, it connect both foil strips, close the circuit and trigger the event.
Open the [code editor](/) and start a new project and add the following blocks. Notice that we are using pin ``P0`` here.
```blocks
basic.showLeds(`
. . . . .
. . . . .
. . # . .
. . . . .
. . . . .
`)
input.onPinPressed(TouchPin.P0, () => {
basic.showLeds(`
# . . . .
# . . . .
# . . . .
# . . . .
# . . . .
`)
})
```
Testing the code with our finger, we see a LED column turn on when pressing both strips.
https://youtu.be/zi_-NAmdDpY
## Upgrading the car
In this lesson, we picked a random toy car and tapped foil to the bottom.
As the car goes through the gate, it will connect both sides of the gate and trigger it. Make sure to add enough foil to get a good connection on the ground.
![](/static/mb/projects/timing-gates/carfoil.jpg "Attaching foil to the car")
By moving the car (slowly) through the gate, you will see that it triggers the ``on pin pressed`` event.
https://youtu.be/M3DIUvDPlIA
### ~hint
It does not work always! Sometimes the foil does not touch long enough both strip to be detected. This is due to the poor quality of our sensor.
To fix this, you would have to consider using better sensors based on IR or Hall effect.
### ~
## Adding the second gate
Repeat the same process with tape and foil to build the first gate.
![](/static/mb/projects/timing-gates/sensor2.jpg "Double foil sensors")
Connect the crocodile plugs to the ``GND`` and ``P1`` pins on the micro:bit.
![](/static/mb/projects/timing-gates/sensormicrobit2.jpg "Sensor and microbit")
## Detecting the second gate
Since the second gate is connected to pin ``P1``, we add a second [on pin pressed](/reference/pins/on-pin-pressed) event
that display 2 columns of LEDs.
```blocks
basic.showLeds(`
. . . . .
. . . . .
. . # . .
. . . . .
. . . . .
`)
input.onPinPressed(TouchPin.P0, () => {
basic.showLeds(`
# . . . .
# . . . .
# . . . .
# . . . .
# . . . .
`)
})
input.onPinPressed(TouchPin.P1, () => {
basic.showLeds(`
# . . . #
# . . . #
# . . . #
# . . . #
# . . . #
`)
})
```
Strolling the car over both gates, you can see how the first gate triggers then the second.
https://youtu.be/N4bWQcu6yWs
## Computing time
The micro:bit has a clock that measures time precisely. It measures how many seconds the micro:bit has been on.
We will record the time where each gate is tripped in variables ``t0`` and ``t1``.
We take the different between ``t1`` and ``t0`` to compute the duration between the gates.
```blocks
let t0 = 0;
let t1 = 0;
basic.showLeds(`
. . . . .
. . . . .
. . # . .
. . . . .
. . . . .
`)
input.onPinPressed(TouchPin.P0, () => {
t0 = control.eventTimestamp();
basic.showLeds(`
# . . . .
# . . . .
# . . . .
# . . . .
# . . . .
`)
})
input.onPinPressed(TouchPin.P1, () => {
t1 = control.eventTimestamp();
basic.showLeds(`
# . . . #
# . . . #
# . . . #
# . . . #
# . . . #
`)
let d = t1 - t0
basic.showNumber(d)
})
```
https://youtu.be/piyym_ux1EM
## Computing velocity
Measure the distance between the gates and apply Newton's laws to compute the velocity of the car.
v = d / t
We'll let you try to code this one on your own!

View File

@ -1,20 +1,11 @@
# Raspberry Pi and Raspbian
It is possible to run the web editor or [command line interface](/cli) from Raspbian on Raspberry Pi 2 or 3.
It is possible to run the web editor or [command line interface](/cli) from Raspbian on Raspberry Pi 2 or 3
with [Raspbian Jessie with Pixel](https://www.raspberrypi.org/downloads/raspbian/).
## Web editor
The web editor requires to install IceWeasel (Firefox) as the built-in browser cannot handle it.
```
sudo apt-get install iceweasel
```
Once installed simply navigate to https://codethemicrobit.com or type
```
firefox https://codethemicrobit.com
```
Starting with **Raspbian Pixel**, Raspbian comes with Chromium. Simply open [](https://codethemicrobit.com).
## Command line

View File

@ -23,13 +23,16 @@ Rather than just sharing the link, you can also embed the project so that your v
### General instructions
* Copy the HTML for embedding the page from the publish dialog. It will look like the following:
Select the kind of embedding you would like.
```html
<div class="ui card sim"><div class="ui content"><div style="position:relative;height:0;padding-bottom:70%;overflow:hidden;"><iframe style="position:absolute;top:0;left:0;width:100%;height:100%;" src="https://codethemicrobit.com/?sandbox=1#pub:httuftrbtg" allowfullscreen="allowfullscreen" frameborder="0"></iframe></div></div></div>
```
* **Screenshot** - a lightweight screenshot of the blocks that links to the snippet
* **Editor** - embedded editor with minimal UI
* **Simulator** - embedded simulator only
* **Command line** - specific instructions to unpack the project using the [command line](/cli) tools
* Open the HTML editor for your blog or website and paste it with your content
Copy the HTML for embedding the page from the publish dialog. It will look like the following:
Open the HTML editor for your blog or website and paste it with your content
### Wordpress

Binary file not shown.

Before

Width:  |  Height:  |  Size: 113 KiB

After

Width:  |  Height:  |  Size: 20 KiB

BIN
docs/static/mb/projects/timing-gates.jpg vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

View File

@ -1,6 +1,7 @@
{
"id": "calliope",
"name": " calliope",
"nickname": "mini",
"title": "calliope - Blocks / Javascript editor",
"description": "A Blocks / JavaScript code editor for the calliope.",
"corepkg": "microbit",
@ -13,8 +14,11 @@
"cloud": {
"workspace": false,
"packages": true,
"sharing": true,
"publish": true,
"preferredPackages": [
]
],
"githubPackages": true
},
"blocksprj": {
"id": "blocksprj",
@ -75,16 +79,6 @@
"aspectRatio": 1.08,
"parts": true,
"partsAspectRatio": 0.69,
"builtinParts": {
"accelerometer": true,
"buttonpair": true,
"ledmatrix": true,
"speaker": true,
"bluetooth": true,
"thermometer": true,
"compass": true,
"headphone": true
},
"boardDefinition": {
"visual": "calliope",
"gpioPinBlocks": [
@ -203,6 +197,8 @@
"footerLogo": "./static/Logo_Calliope_Woman.svg",
"cardLogo": "https://az851932.vo.msecnd.net/pub/drbwxcth",
"appLogo": "https://az851932.vo.msecnd.net/pub/tbhemtig",
"organization": "Microsoft",
"organizationUrl": "https://calliope.cc/",
"organizationLogo": "./static/Microsoft-logo_rgb_c-gray.png",
"homeUrl": "https://calliope.cc/",
"privacyUrl": "https://go.microsoft.com/fwlink/?LinkId=521839",

View File

@ -114,6 +114,11 @@ namespace pxsim.pins {
export function i2cWriteBuffer(address: number, buf: RefBuffer, repeat?: boolean): void {
// fake - noop
}
// this likely shouldn't be called
export function getPinAddress(name: number) {
return getPin(name)
}
}
namespace pxsim.devices {

View File

@ -7,4 +7,4 @@ export KS_FORCE_CLOUD=yes
(cd libs/lang-test0; node ../../node_modules/pxt-core/built/pxt.js test)
(cd libs/lang-test1; node ../../node_modules/pxt-core/built/pxt.js test)
node node_modules/pxt-core/built/pxt.js testdir tests
(cd libs/hello; node ../../node_modules/pxt-core/built/pxt.js testconv https://az851932.vo.msecnd.net/files/td-converter-tests-v0.json)
(cd libs/hello; node ../../node_modules/pxt-core/built/pxt.js testconv https://az851932.vo.msecnd.net/files/td-converter-tests-v1.json)