docs cleanup
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
# banana keyboard
|
||||
|
||||
### @description A beginner maker activity, building a piano from bananas.
|
||||
|
||||
### ~avatar
|
||||
|
||||
Build your own @boardname@ piano using bananas!
|
||||
|
||||
### ~
|
||||
|
||||

|
||||
|
||||
## Duration: ~20 minutes.
|
||||
|
||||
## Materials
|
||||
|
||||
* @boardname@, battery holder and 2 AAA batteries
|
||||
* Bananas
|
||||
* Orange
|
||||
* Crocodile clips
|
||||
|
||||
## Activities
|
||||
|
||||
* [Making the keyboard](/projects/banana-keyboard/make)
|
||||
* [Beat box](/projects/banana-keyboard/beat-box)
|
||||
|
||||
### ~button /projects/banana-keyboard/make
|
||||
Let's get started!
|
||||
### ~
|
||||
@@ -1,54 +0,0 @@
|
||||
# banana keyboard - beat box
|
||||
|
||||
Have you ever tried to making beat box sounds? Let's try making a beatbox with code!
|
||||
|
||||
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.
|
||||
|
||||
```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.
|
||||
|
||||
```blocks
|
||||
let sound = music.noteFrequency(Note.A);
|
||||
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.
|
||||
|
||||
```blocks
|
||||
let sound = music.noteFrequency(Note.A);
|
||||
|
||||
input.onPinPressed(TouchPin.P1, () => {
|
||||
for (let i = 0; i < 4; i++) {
|
||||
sound = sound + 25
|
||||
}
|
||||
})
|
||||
|
||||
input.onPinPressed(TouchPin.P2, () => {
|
||||
for (let i = 0; i < 4; i++) {
|
||||
sound = sound - 25
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
* click *Download* to see if the code works as expected.
|
||||
@@ -1,85 +0,0 @@
|
||||
# banana keyboard - making
|
||||
|
||||
## Materials
|
||||
|
||||
* @boardname@, battery holder and 2 AAA batteries
|
||||
* Bananas
|
||||
* Orange
|
||||
* Crocodile clips
|
||||
|
||||
## Steps
|
||||
|
||||
### Step 1
|
||||
|
||||

|
||||
|
||||
Using the 1st crocodile clip, connect the end of the crocodile clip onto GND pin on the @boardname@.
|
||||
|
||||
### Step 2
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
Using the 2nd crocodile clip, connect the end of the crocodile clip onto the 0 pin on the @boardname@.
|
||||
|
||||
### Step 3
|
||||
|
||||

|
||||
|
||||
Using the 1st crocodile clip, connect the second end of the crocodile clip onto based of the headphone jack.
|
||||
|
||||
### Step 4
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
Using the 2nd crocodile clip, connect the second end of the crocodile clip onto tip of the headphone jack.
|
||||
|
||||
### Step 5
|
||||
|
||||

|
||||
|
||||
Using the 3rd crocodile clip, connect the end of the crocodile clip onto the 1st crocodile clip already clipped onto GND.
|
||||
|
||||
### Step 6
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
Using the 3rd crocodile clip, connect the unattached end of the crocodile clip onto the orange.
|
||||
|
||||
### Step 7
|
||||
|
||||

|
||||
|
||||
Using the 4th crocodile clip, connect the end of the crocodile clip onto pin 1 on the @boardname@.
|
||||
|
||||
### Step 8
|
||||
|
||||

|
||||
|
||||
Using the 4th crocodile clip, connect the unattached end of the crocodile clip onto the banana.
|
||||
|
||||
### Step 9
|
||||
|
||||

|
||||
|
||||
Your banana keyboard is ready!
|
||||
|
||||
### Step 10
|
||||
|
||||
Connect your @boardname@ 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
|
||||
### ~
|
||||
@@ -1,105 +0,0 @@
|
||||
# compass
|
||||
|
||||

|
||||
|
||||
Display the direction that the @boardname@ is facing using the compass
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Welcome! This guided tutorial will show you how to program a script that displays the direction the @boardname@ is pointing. Let's get started!
|
||||
|
||||
### ~
|
||||
|
||||
|
||||
## Step 1
|
||||
|
||||
Create a loop that will continuously update the reading of the compass.
|
||||
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
|
||||
})
|
||||
```
|
||||
|
||||
## Step 2
|
||||
|
||||
Store the reading of the @boardname@ in a variable called `degrees`.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
let degrees = input.compassHeading()
|
||||
})
|
||||
```
|
||||
|
||||
## Step 3
|
||||
|
||||
If `degrees` is less than `45`, then the compass heading is mostly pointing toward North. Display `N` on the @boardname@.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
let degrees = input.compassHeading();
|
||||
if (degrees < 45) {
|
||||
basic.showString("N");
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## Step 4
|
||||
|
||||
If `degrees` is less than 135, the @boardname@ is mostly pointing East. Display `E` on the @boardname@.
|
||||
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
let degrees = input.compassHeading();
|
||||
if (degrees < 45) {
|
||||
basic.showString("N");
|
||||
}
|
||||
else if (degrees < 135) {
|
||||
basic.showString("E");
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## Step 5
|
||||
|
||||
If `degrees` is less than 225, the @boardname@ is mostly pointing South. Display `S` on the @boardname@.
|
||||
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
let degrees = input.compassHeading();
|
||||
if (degrees < 45) {
|
||||
basic.showString("N");
|
||||
}
|
||||
else if (degrees < 135) {
|
||||
basic.showString("E");
|
||||
}
|
||||
else if (degrees < 225) {
|
||||
basic.showString("S");
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## Step 6
|
||||
|
||||
If none of these conditions returned true, then the @boardname@ must be pointing West. Display `W` on the @boardname@.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
let degrees = input.compassHeading();
|
||||
if (degrees < 45) {
|
||||
basic.showString("N");
|
||||
}
|
||||
else if (degrees < 135) {
|
||||
basic.showString("E");
|
||||
}
|
||||
else if (degrees < 225) {
|
||||
basic.showString("S");
|
||||
}
|
||||
else {
|
||||
basic.showString("W");
|
||||
}
|
||||
});
|
||||
```
|
||||
@@ -1,121 +0,0 @@
|
||||
# flashing heart
|
||||
|
||||

|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
```sim
|
||||
basic.forever(() => {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
# # # # #
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .`
|
||||
);
|
||||
basic.pause(500);
|
||||
basic.clearScreen();
|
||||
basic.pause(500);
|
||||
})
|
||||
```
|
||||
|
||||
Use the LEDs to display a flashing heart, and then create
|
||||
an animation of a broken heart. :(
|
||||
|
||||
### ~
|
||||
|
||||
## Step 1
|
||||
|
||||
Use [show leds](/reference/basic/show-leds) and make your code look like this:
|
||||
|
||||
```blocks
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
# # # # #
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .`
|
||||
);
|
||||
```
|
||||
|
||||
## Step 2
|
||||
|
||||
Add a [pause](/reference/basic/pause) to wait and [clear screen](/reference/basic/clear-screen) to turn off the LEDs.
|
||||
|
||||
```blocks
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
# # # # #
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .`);
|
||||
basic.pause(500);
|
||||
basic.clearScreen();
|
||||
```
|
||||
|
||||
## Step 3
|
||||
|
||||
Put a [forever loop](/reference/basic/forever) around it.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
# # # # #
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .`
|
||||
);
|
||||
basic.pause(500);
|
||||
basic.clearScreen();
|
||||
})
|
||||
```
|
||||
|
||||
## Step 4
|
||||
|
||||
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);
|
||||
})
|
||||
```
|
||||
|
||||
## Step 5
|
||||
|
||||
Add a second image of a broken heart.
|
||||
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
# # # # #
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .`
|
||||
);
|
||||
basic.pause(500);
|
||||
basic.clearScreen();
|
||||
basic.pause(500);
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
# . # # #
|
||||
# . . . #
|
||||
. # # # .
|
||||
. . # . .`
|
||||
);
|
||||
basic.pause(500);
|
||||
basic.clearScreen();
|
||||
basic.pause(500);
|
||||
})
|
||||
```
|
||||
@@ -1,42 +0,0 @@
|
||||
# Guitar
|
||||
|
||||

|
||||
|
||||
### @description A beginner-intermediate maker activity, building a guitar with the @boardname@
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Make a @boardname@ guitar with this guided tutorial!
|
||||
|
||||
### ~
|
||||
*playing @boardname@ guitar*
|
||||
https://youtu.be/GYmdTFvxz80
|
||||
|
||||
## Duration
|
||||
|
||||
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)
|
||||
* Markers and/or paint
|
||||
* Aluminum Foil
|
||||
* Scissors that can cut cardboard
|
||||
* 1 @boardname@, battery holder and 2 AAA batteries
|
||||
* 4-5 Crocodile clips
|
||||
* Headphones
|
||||
|
||||
## Activities
|
||||
|
||||
* [Making the Guitar Body](/projects/guitar/make)
|
||||
* [Buttons, Display & Sound](/projects/guitar/displaybuttons)
|
||||
* [Light Sensor Tone control](/projects/guitar/lightsensor)
|
||||
* [Accelerometer Beat control](/projects/guitar/accelerometer)
|
||||
* [Pin Press Switch](/projects/guitar/pinpress)
|
||||
|
||||
### ~button /projects/guitar/make
|
||||
|
||||
Let's get started!
|
||||
|
||||
### ~
|
||||
@@ -1,115 +0,0 @@
|
||||
# Accelerometer Beat control
|
||||
|
||||
### @description @boardname@ guitar: using accelerometer to control tempo
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Use the Accelerometer to control guitar tempo
|
||||
* Concepts:
|
||||
* Gravity
|
||||
* Acceleration
|
||||
* X, Y, Z coordinates
|
||||
* Tempo
|
||||
* Beat
|
||||
* Mapping
|
||||
* Graphing
|
||||
* Absolute value
|
||||
|
||||
### ~
|
||||
|
||||
## Duration: 30 - 45 minutes
|
||||
|
||||
*accelerometer controlled tempo*
|
||||
https://youtu.be/kA0HpqCWsjs
|
||||
|
||||
## Blocks
|
||||
|
||||
```cards
|
||||
input.acceleration(Dimension.Y)
|
||||
music.setTempo(120)
|
||||
pins.map(0, 0, 1023,60, 320)
|
||||
Math.abs(1)
|
||||
```
|
||||
|
||||
## Accelerometer, gravity and tilting!
|
||||
|
||||
The @boardname@ contains an **accelerometer** sensor that is able to measure forces applied to the board.
|
||||
On earth, we are subject to the **gravity force** which pulls us to the ground!
|
||||
|
||||
https://youtu.be/0SULoTKmkhI
|
||||
|
||||
When the @boardname@ is flat on a table, with the screen pointing up, the gravity force is aligned
|
||||
with the **Z** axis of the @boardname@.
|
||||
|
||||

|
||||
|
||||
If you tilt it up and down, the force will align with the **Y** axis -- this is how we can detect tilting!!!
|
||||
If the force along **Y** grows, the @boardname@ is tilting more and more vertically!
|
||||
|
||||
## Measuring Acceleration along different coordinates (X, Y, Z axis)
|
||||
|
||||
The acceleration block approximately measures **milli-g**, which is 1/1000 of a **g** or the
|
||||
acceleration of gravity.
|
||||
|
||||
### Step 1: Graphing acceleration
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
led.plotBarGraph(input.acceleration(Dimension.Y), 1023)
|
||||
})
|
||||
```
|
||||
**Create the code** that measures the change in the Y axis acceleration as a graph on the LEDs
|
||||
|
||||
**Dowload the code** to the @boardname@
|
||||
|
||||
**Test the movements that move the graph from 1 to 5 bars on the LEDs**
|
||||
|
||||
### Extra
|
||||
|
||||
Try graphing the acceleration along the **X** and **Z** axis. Can you explain the differences?
|
||||
|
||||
### ~hint
|
||||
## Mapping
|
||||
**It is common to map one standard to another - such as with temperature**
|
||||

|
||||
### ~
|
||||
|
||||
### Step 2: Mapping acceleration to Beat
|
||||
**@boardname@ sensors produce signal values between 0 to 1023. The *[map block](/reference/pins/map)* converts the signal to a desired range.**
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
music.setTempo(pins.map(Math.abs(input.acceleration(Dimension.Y)),
|
||||
0, 1023,
|
||||
60, 320))
|
||||
music.playTone(Note.C, music.beat(BeatFraction.Quarter));
|
||||
})
|
||||
```
|
||||
|
||||
**Create the code** that *Maps* Y axis acceleration as *tempo*
|
||||
|
||||
**Download the code** to the @boardname@ on the guitar
|
||||
|
||||
**Test the movements that speed and slow the tempo**
|
||||
|
||||
### Step 3: Combine with light sensor tone control
|
||||
**Put it all together!**
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
music.setTempo(pins.map(Math.abs(input.acceleration(Dimension.Y)),
|
||||
0, 1023,
|
||||
60, 320))
|
||||
music.playTone(
|
||||
input.lightLevel() * 25,
|
||||
music.beat(BeatFraction.Quarter)
|
||||
);
|
||||
})
|
||||
```
|
||||
**Combine the code above with the light sensor tone control code from the previous activity**
|
||||
|
||||
**Download the code** to the @boardname@ on the guitar
|
||||
|
||||
### Now play the guitar adjusting tone and tempo using the light sensor and accelerometer!
|
||||
|
||||
### ~button /projects/guitar/pinpress
|
||||
NEXT: Pin Press on/off
|
||||
### ~
|
||||
@@ -1,179 +0,0 @@
|
||||
# Buttons, Display & Sound
|
||||
### @description @boardname@ guitar: using buttons with display and sound
|
||||
|
||||
### ~avatar avatar
|
||||
Use Button Events to control LED Display and play Sound
|
||||
* **Concepts:**
|
||||
* Events
|
||||
* Tone/Note
|
||||
* Sequence
|
||||
|
||||
### ~
|
||||
|
||||
## Duration: 30 - 45 minutes
|
||||
|
||||
## Materials
|
||||
|
||||
A @boardname@, battery pack and 2 x AAA batteries
|
||||
|
||||

|
||||
|
||||
2 to 4 crocodile clips
|
||||
|
||||

|
||||
|
||||
Headphones
|
||||
|
||||

|
||||
|
||||
## Blocks
|
||||
|
||||
```cards
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # # # .
|
||||
. # . # .
|
||||
. # # # .
|
||||
`);
|
||||
input.onButtonPressed(Button.A, () => {});
|
||||
music.playTone(Note.C, music.beat(BeatFraction.Quarter))
|
||||
music.rest(music.beat(BeatFraction.Whole))
|
||||
music.beat(BeatFraction.Quarter)
|
||||
```
|
||||
|
||||
## Step 1: Make a Smiley
|
||||
Open @homeurl@ in your web browser
|
||||
```blocks
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # # # .
|
||||
. # . # .
|
||||
. # # # .
|
||||
`);
|
||||
```
|
||||
From **Basics**, drag a **show LEDs** block into the coding area
|
||||
* Create a face with LEDs
|
||||
|
||||

|
||||
Connect your @boardname@ to your computer via USB and click **`Download`**.
|
||||
Follow the instructions to move the code to your @boardname@.
|
||||
|
||||
## Step 2: Add Smiley LED Button Events
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # # # .
|
||||
. # . # .
|
||||
. # # # .
|
||||
`)
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. . . . .
|
||||
# . . . #
|
||||
. # # # .
|
||||
`)
|
||||
})
|
||||
```
|
||||
|
||||
From **Input**, drag an **on button 'A' pressed** block into the coding area
|
||||
|
||||
* Snap the LED face into the block
|
||||
|
||||
* Create a 'B' button block with a different LED face
|
||||
|
||||
* Download the code to your @boardname@ and try the A & B buttons
|
||||
|
||||
|
||||
## Step 3: Add Headphone Speakers using Crocodile clips
|
||||
|
||||

|
||||
|
||||

|
||||
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
|
||||
|
||||
*attaching batteries and @boardname@*
|
||||
https://youtu.be/zwRTmpKIaVU
|
||||
Attach the @boardname@ & battery-pack to the guitar body
|
||||
|
||||
*connecting headphone speaker*
|
||||
https://youtu.be/ewyEW_U5G9M
|
||||
Connect the headphones with crocodile clips
|
||||
|
||||
### ~hint
|
||||
## The @boardname@ can play music
|
||||
|
||||
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, () => {
|
||||
music.playTone(Note.C, music.beat(BeatFraction.Quarter))
|
||||
music.rest(music.beat(BeatFraction.Whole))
|
||||
music.playTone(Note.C, music.beat(BeatFraction.Quarter))
|
||||
music.rest(music.beat(BeatFraction.Whole))
|
||||
music.playTone(Note.D, music.beat(BeatFraction.Quarter))
|
||||
music.rest(music.beat(BeatFraction.Whole))
|
||||
music.playTone(Note.C, music.beat(BeatFraction.Quarter))
|
||||
music.rest(music.beat(BeatFraction.Whole))
|
||||
music.rest(music.beat(BeatFraction.Whole))
|
||||
music.playTone(Note.F, music.beat(BeatFraction.Half))
|
||||
music.rest(music.beat(BeatFraction.Whole))
|
||||
music.playTone(Note.E, music.beat(BeatFraction.Whole))
|
||||
})
|
||||
```
|
||||
### ~
|
||||
## Step 4: Add Tone Playing Events for Buttons A & B
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # # # .
|
||||
. # . # .
|
||||
. # # # .
|
||||
`)
|
||||
music.playTone(Note.A, music.beat(BeatFraction.Whole))
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. . . . .
|
||||
# . . . #
|
||||
. # # # .
|
||||
`)
|
||||
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**
|
||||
|
||||
* 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 @boardname@
|
||||
|
||||
**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
|
||||
* *Tip*: Search for "ABC music notation" or "Easy Music Notes" + the name of a song
|
||||
|
||||
## Extra
|
||||
|
||||
* [Smiley Buttons tutorial](/projects/smiley-buttons)
|
||||
* [Hack your headphones](/projects/hack-your-headphones)
|
||||
|
||||
|
||||
### ~button /projects/guitar/lightsensor
|
||||
NEXT: Light Sensor Tone Control
|
||||
### ~
|
||||
@@ -1,115 +0,0 @@
|
||||
# Light Sensor Tone control
|
||||
|
||||
### @description @boardname@ guitar: using light sensor to control tone
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
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
|
||||
### ~
|
||||
|
||||
## Duration: 30 - 45 minutes
|
||||
|
||||
*playing tones with light sensor*
|
||||
https://youtu.be/2cKg9pokVC4
|
||||
|
||||
## The @boardname@ LEDs Light Sensors
|
||||
|
||||
- the @boardname@ 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 measure the current light level and control the tone
|
||||
|
||||
## Forever Loop
|
||||
|
||||
The forever loop really does run forever. The forever loop is useful when there is a need to continually check for an event or use a changing value in code.
|
||||
|
||||
## Blocks
|
||||
|
||||
```cards
|
||||
basic.forever(() => {})
|
||||
input.lightLevel()
|
||||
led.plotBarGraph(0, 255)
|
||||
music.playTone(Note.C, music.beat(BeatFraction.Quarter))
|
||||
```
|
||||
|
||||
## Step 1: Create a light level detector
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
led.plotBarGraph(input.lightLevel(), 255)
|
||||
})
|
||||
```
|
||||
**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* **
|
||||
|
||||
## Step 2: Test the light required to move the bar graph height
|
||||
|
||||
*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 @boardname@ + 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 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*
|
||||
|
||||
### 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 @boardname@**
|
||||
|
||||
**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
|
||||
|
||||
## Good work, this guitar is sounding good!
|
||||
**Challenge:** Create a variable for the light level multiplier that you can change using buttons (optional)
|
||||
|
||||
### ~button /projects/guitar/accelerometer
|
||||
NEXT: Accelerometer Beat control
|
||||
### ~
|
||||
@@ -1,59 +0,0 @@
|
||||
# Making the Guitar Body
|
||||
### @description Maker Project for Guitar Body for @boardname@
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Make the Guitar Body for your @boardname@ Guitar
|
||||
|
||||
### ~
|
||||
|
||||
## Duration: ~45 minutes
|
||||
|
||||
## Materials
|
||||
* Cardboard large pieces (recycle!)
|
||||
* Tape (masking, duct tape, and/or packing tape)
|
||||
* Scissors that can cut cardboard
|
||||
* Markers and/or paint
|
||||
|
||||

|
||||
|
||||
## Step 1: Design the body
|
||||
*tracing the guitar design*
|
||||
https://youtu.be/xMSrWaOZkFg
|
||||
|
||||
* Search for [Guitar Silhouette](https://www.bing.com/images/search?q=Guitar+Silhouettes) design ideas and customize
|
||||
the shape of your guitar
|
||||
* Trace the design on a flat piece of cardboard (40-80 cm is best)
|
||||
|
||||
### ~hint
|
||||
|
||||
* Avoid small details that are difficult to cut into cardboard
|
||||
* Unfolding a box gives longer pieces of cardboard and creases can be reinforced
|
||||
|
||||
### ~
|
||||
|
||||
## Step 2: Cut out the body
|
||||
*cutting the cardboard*
|
||||
https://youtu.be/aUQkrFoEank
|
||||
|
||||
|
||||
## Step 3: Personalize the Guitar
|
||||
|
||||
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!
|
||||
|
||||

|
||||
|
||||
## Extra!
|
||||
*strengthening the guitar*
|
||||
https://youtu.be/q0GkQdJmxjE
|
||||
|
||||
Strengthen the guitar next with an angled cardboard strip (*optional*).
|
||||
|
||||
### ~button /projects/guitar/displaybuttons
|
||||
NEXT: Buttons, Display and Sound
|
||||
### ~
|
||||
@@ -1,131 +0,0 @@
|
||||
# Pin Press Switch
|
||||
|
||||
### @description @boardname@ guitar: use pin press to toggle guitar play on/off
|
||||
|
||||
### ~avatar avatar
|
||||
Use pin press to switch guitar play on/off
|
||||
|
||||
* Concepts:
|
||||
* Circuit
|
||||
* Conductor
|
||||
* Variable/Global-Variable
|
||||
* Conditional: **`if`**, **`else`**
|
||||
* Boolean: **`True`/`False`**
|
||||
### ~
|
||||
|
||||
## Duration: approximately 45 minutes
|
||||
|
||||
## Materials:
|
||||
2-3 Crocodile clips
|
||||
|
||||
## Blocks
|
||||
|
||||
```cards
|
||||
var on = false
|
||||
on;
|
||||
if (on) { } else {}
|
||||
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
|
||||
|
||||
**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!**
|
||||
### ~
|
||||
|
||||
## Step 1: Pin Press Test
|
||||
|
||||
```blocks
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
basic.showNumber(0)
|
||||
})
|
||||
input.onPinPressed(TouchPin.P1, () => {
|
||||
basic.showNumber(1)
|
||||
})
|
||||
input.onPinPressed(TouchPin.P2, () => {
|
||||
basic.showNumber(2)
|
||||
})
|
||||
```
|
||||
**Create the pin-press code**
|
||||
|
||||
**Download the code** on the @boardname@
|
||||
|
||||
https://youtu.be/PAIU-vHqyGU
|
||||
|
||||
**Hold the @boardname@ 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 @boardname@ 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**
|
||||
|
||||
**Connect the foil to `GND` using a crocodile clip**
|
||||
|
||||
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 @boardname@**
|
||||
**between ON and OFF**
|
||||
```blocks
|
||||
let on = false
|
||||
basic.forever(() => {
|
||||
if (on == true) {
|
||||
basic.showString("ON")
|
||||
} else {
|
||||
basic.showString("OFF")
|
||||
}
|
||||
})
|
||||
input.onPinPressed(TouchPin.P1, () => {
|
||||
if (on == true) {
|
||||
on = false
|
||||
} else {
|
||||
on = true
|
||||
}
|
||||
})
|
||||
```
|
||||
**Create the ON/OFF switch code**
|
||||
|
||||
**Download the code on the @boardname@**
|
||||
|
||||
**Test by touching `P1` to toggle the LED message between ON and OFF**
|
||||
|
||||
*Final code*
|
||||
TODO: do we want to use `on = !on;` or be more direct in flipping the switch? `on = true; on = false;`
|
||||
```blocks
|
||||
var on = false
|
||||
basic.forever(() => {
|
||||
if (on) {
|
||||
music.setTempo(pins.map(Math.abs(input.acceleration(Dimension.Y)),
|
||||
0, 1023,
|
||||
60, 320))
|
||||
music.playTone(
|
||||
input.lightLevel() * 25,
|
||||
music.beat(BeatFraction.Quarter)
|
||||
);
|
||||
} else {
|
||||
music.rest(music.beat())
|
||||
}
|
||||
})
|
||||
input.onPinPressed(TouchPin.P1, () => {
|
||||
on = !on;
|
||||
})
|
||||
```
|
||||
## 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
|
||||
@@ -1,37 +0,0 @@
|
||||
# hack your headphones
|
||||
|
||||
### @description A beginner maker activity, building a piano from bananas.
|
||||
|
||||
### ~avatar
|
||||
|
||||
Build your own music player @boardname@ from headphones.
|
||||
|
||||
### ~
|
||||
|
||||

|
||||
|
||||
|
||||
## Duration: ~15 minutes.
|
||||
|
||||
## Materials
|
||||
|
||||
* @boardname@, battery holder and 2 AAA batteries
|
||||
* Headphones
|
||||
* Crocodile clips
|
||||
|
||||
## Activities
|
||||
|
||||
* [Connect your headphone](/projects/hack-your-headphones/make)
|
||||
* [Play sounds!]()
|
||||
|
||||
# ~hint
|
||||
|
||||
**No crocodile clips!?!?!** Use wires or Aluminium foil! [Read more...](/device/foil-circuits)
|
||||
|
||||
# ~
|
||||
|
||||
### ~button /projects/hack-your-headphones/make
|
||||
|
||||
Let's get started!
|
||||
|
||||
### ~
|
||||
@@ -1,53 +0,0 @@
|
||||
# hack your headphones - making
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Did you know you could attach your headhpones to the @boardname@ to generate sounds?
|
||||
|
||||
### ~
|
||||
|
||||
# ~hint
|
||||
|
||||
**No crocodile clips!?!?!** Use wires or Aluminium foil! [Read more...](/device/foil-circuits)
|
||||
|
||||
# ~
|
||||
|
||||
### Step 1
|
||||
|
||||

|
||||
|
||||
Using the 1st crocodile clip, connect the end of the crocodile clip onto GND pin on the @boardname@.
|
||||
|
||||
### Step 2
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
Using the 2nd crocodile clip, connect the end of the crocodile clip onto the 0 pin on the @boardname@.
|
||||
|
||||
### Step 3
|
||||
|
||||

|
||||
|
||||
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 @boardname@.
|
||||
|
||||
### Step 4
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
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 @boardname@ pin 0 to the tip of the right side of your headphone. Use the tip of the headphone jack to play sounds.
|
||||
|
||||
### Step 5
|
||||
|
||||

|
||||
|
||||
You hacked your headphones!
|
||||
|
||||
### ~button /projects/hack-your-headphones/music-of-light
|
||||
|
||||
NEXT: music of light
|
||||
|
||||
### ~
|
||||
@@ -1,70 +0,0 @@
|
||||
# hack your headphones - music of light
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Have you ever tried to making beat box sounds based on the light level? Let's try making a beatbox with code!
|
||||
|
||||
### ~
|
||||
|
||||
Let's start by adding a variable where you can store data. Then rename the variable to "light". Then set the value of the variable to the block `light level` from the Input drawer. This will gets the `light level` from 0 (dark) to 255 (bright). The light is measured by using various LEDs from the screen. Modify your code so that your code looks like this.
|
||||
|
||||
|
||||
```blocks
|
||||
let light = input.lightLevel();
|
||||
```
|
||||
|
||||
We want to play music on button pressed in order to register an event handler that will execute whenever when you run a script and click on button pressed on the simulator. We must start by opening the Input drawer and adding `on button pressed` A. Then add a block `rest` to plays nothing for a `1/16` beat. Modify your code so that your code looks like this.
|
||||
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
music.rest(music.beat(BeatFraction.Sixteenth));
|
||||
let light = input.lightLevel();
|
||||
});
|
||||
```
|
||||
|
||||
We click on the Logic drawer then insert a `if do` that will conditionally run code depending on whether the Boolean condition is true or false. Then insert the variable `light` into the first part of the inequality. The variable "light" will appear in the Variables drawer. Finally, we insert 25. Modify your code so that your code looks like this. If the `light level` is `less than` 25, play `ring tone` `C`. If this conditions is not true, play `ring tone` `A`.
|
||||
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
music.rest(music.beat(BeatFraction.Sixteenth));
|
||||
let light = input.lightLevel();
|
||||
if (light < 25) {
|
||||
music.ringTone(music.noteFrequency(Note.C));
|
||||
}
|
||||
else {
|
||||
music.ringTone(music.noteFrequency(Note.A));
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
We click on the Logic drawer then insert a `less than` sign into the first `if` conditional that will conditionally run code depending on whether the Boolean condition is true or false. Continue this logic to continue with these conditional statements. Click on the Logic drawer. Then we want to add additional conditional statements by clicking on the gear to the left of the `if`. Add 05 `else if` and 01 `else` inside the `if do` block structure. If the `light level` is `less than` 50, play `ring tone` ``D``. If the `light level` is `less than` 100, play `ring tone` ``E``. If the `light level` is `less than` 150, play `ring tone` ``F`` If the `light level` is `less than` 180, play `ring tone` ``G``. If these conditions are not true, `ring tone` ``A``.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
music.rest(music.beat(BeatFraction.Sixteenth));
|
||||
let light = input.lightLevel();
|
||||
if (light < 25) {
|
||||
music.ringTone(music.noteFrequency(Note.C));
|
||||
}
|
||||
else if (light < 50) {
|
||||
music.ringTone(music.noteFrequency(Note.D));
|
||||
}
|
||||
else if (light < 100) {
|
||||
music.ringTone(music.noteFrequency(Note.E));
|
||||
}
|
||||
else if (light < 150) {
|
||||
music.ringTone(music.noteFrequency(Note.F));
|
||||
}
|
||||
else if (light < 180) {
|
||||
music.ringTone(music.noteFrequency(Note.G));
|
||||
}
|
||||
else {
|
||||
music.ringTone(music.noteFrequency(Note.A));
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
* click **Download** and run your code on the @boardname@.
|
||||
@@ -1,50 +0,0 @@
|
||||
# love meter
|
||||
|
||||

|
||||
|
||||
Use pins P0, P1 and P2 to change the display by creating a circuit with your body.
|
||||
|
||||
## Step 1
|
||||
|
||||
Use [on pin pressed](/reference/input/on-pin-pressed) to show a random number
|
||||
when pin P0 is pressed (hold the GND pin with other hand):
|
||||
|
||||
```blocks
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
basic.showNumber(Math.random(11));
|
||||
});
|
||||
```
|
||||
## Step 2
|
||||
|
||||
Show a string when pin P1 is pressed:
|
||||
|
||||
```blocks
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
basic.showNumber(Math.random(11));
|
||||
});
|
||||
input.onPinPressed(TouchPin.P1, () => {
|
||||
basic.showString("LOVE?");
|
||||
});
|
||||
```
|
||||
|
||||
## Step 3
|
||||
|
||||
Show a heart when pin P2 is pressed:
|
||||
|
||||
```blocks
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
basic.showNumber(Math.random(11));
|
||||
});
|
||||
input.onPinPressed(TouchPin.P1, () => {
|
||||
basic.showString("LOVE?");
|
||||
});
|
||||
input.onPinPressed(TouchPin.P2, () => {
|
||||
basic.showLeds(`
|
||||
. # # # .
|
||||
# # # # #
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .
|
||||
`);
|
||||
});
|
||||
```
|
||||
@@ -1,101 +0,0 @@
|
||||
# magic button trick
|
||||
|
||||
Perform a magic trick where you appear to make the **A** and **B** button of your @boardname@ swap over just by moving a sticky label.
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Welcome! This activity will teach you how to use the @boardname@'s compass to detect a nearby magnet
|
||||
|
||||
### ~
|
||||
This is a simple magic trick you can perform to amaze your friends, where by moving the sticky labels on your @boardname@'s **A** and **B** button you appear to make the buttons really switch over. To see the trick performed watch the video below.
|
||||
|
||||
https://youtu.be/-9KvmPopov8
|
||||
|
||||
## How the trick works
|
||||
|
||||
Unfortunately, the only magic here is in the code. This trick uses a magnet, hidden in your hand, to tell the @boardname@ to swap over the buttons so that when the magnet is near the microbit the **A** button starts working like the **B** button and the **B** button starts working like the **A** button.
|
||||
|
||||
## What you need
|
||||
|
||||
The only things you need for this trick are your @boardname@ and any magnet that is small enough to fit in your hand, even a fridge magnet will work.
|
||||
|
||||

|
||||
|
||||
|
||||
## Step 1: getting the buttons to display **A** and **B**
|
||||
|
||||
Before we code the trick itself, we need to get the buttons working as you would expect them to so that pressing button **A** displays 'A' and pressing button **B** displays 'B':
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.showString("A")
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
basic.showString("B")
|
||||
})
|
||||
```
|
||||
|
||||
## Step 2: measuring magnetic force
|
||||
|
||||
We will use the @boardname@'s compass to detect the magnet. Compass's tell us what direction we are pointing by detecting the Earth's magnetic field but they can also detect any other magnet nearby. We will use that to check if our magnet is next to the @boardname@ by using the [magnetic force](/reference/input/magnetic-force) block found in the input menu's 'more' section. As we only want to measure the strength we change the drop down to select 'strength':
|
||||
|
||||
```blocks
|
||||
input.magneticForce(Dimension.Strength)
|
||||
```
|
||||
|
||||
## Step 3: checking if the magnetic is nearby
|
||||
|
||||
Now we can measure the magnetic force near the microbit, we can check if the value we measure is so big that it means there must be a strong magnet nearby.
|
||||
|
||||
If you have ever played with magnets you know they have two ends, often called a north and south 'pole'. Depending on which end of the magnet is pointing at the microbit the magnetic force measurement will either be a negative number like -100 or a positive number like 100. We just want to know if the strength is at least 100 we don't care if its negative or positive so we also use the 'absolute value of' block from the maths menu to tell our code to ignore the negative sign and just treat -100 as if its 100.
|
||||
|
||||
So in the code below we will check if the absolute value of our magnetic field strength reading is more than 100 and save the result of that check in a new variable called 'isSwitched':
|
||||
|
||||
```blocks
|
||||
let isSwitched = Math.abs(input.magneticForce(Dimension.Strength)) > 100
|
||||
```
|
||||
## Step 4: running our 'magnet nearby' check all the time
|
||||
|
||||
At the moment our code to detect the magnet being nearby will only run once so we need to put it into a [forever](/reference/basic/forever) block so that it keeps getting run again and again checking for the magnet to come near to the @boardname@. We should also make sure 'isSwitched' is false when our program starts.
|
||||
|
||||
```blocks
|
||||
let isSwitched = false;
|
||||
basic.forever(() => {
|
||||
let isSwitched = Math.abs(input.magneticForce(Dimension.Strength)) > 100
|
||||
})
|
||||
```
|
||||
|
||||
## Step 5: swapping the buttons when we know the magnet is nearby
|
||||
|
||||
Now we can check the value of our variable 'isSwitched' whenever we want and we will know that the magnet is nearby if it's value is 'true'. Let's use that to change how the buttons work and complete the code for our trick. We will add an 'if, else' block to each button's code and check if we should swap over what each button displays because 'isSwitched' is equal to true:
|
||||
|
||||
```blocks
|
||||
|
||||
let isSwitched = false;
|
||||
basic.forever(() => {
|
||||
isSwitched = Math.abs(input.magneticForce(Dimension.Strength)) > 100
|
||||
})
|
||||
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
if (isSwitched) {
|
||||
basic.showString("B")
|
||||
} else {
|
||||
basic.showString("A")
|
||||
}
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
if (isSwitched) {
|
||||
basic.showString("A")
|
||||
} else {
|
||||
basic.showString("B")
|
||||
}
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
## step 5: practice your performance
|
||||
Now you just need to program your own @boardname@ and practice the trick a few times before performing to friends. Try asking your friends to click the buttons after you have switched the labels and the trick won't work for them as they don't have a hidden magnet in their hand.
|
||||
|
||||
|
||||
## about the authors
|
||||
This project was contributed by Brian and Jasmine Norman, aka [@MicroMonstersUK](https://twitter.com/MicroMonstersUK). You can chekout their [@boardname@ tutorials chanel on youtube](https://www.youtube.com/channel/UCK2DviDexh_Er2QYZerZyZQ) for more projects.
|
||||
@@ -1,65 +0,0 @@
|
||||
# messenger
|
||||
|
||||

|
||||
|
||||
Use the radio to create an app that sends "YO" messages.
|
||||
|
||||
## Step 1
|
||||
|
||||
Use [on button pressed](/reference/input/on-button-pressed) to send the number "0" over radio.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
radio.sendNumber(0);
|
||||
});
|
||||
```
|
||||
|
||||
## Step 2
|
||||
|
||||
Use [radio on data packet received](/reference/radio/on-data-packet-received) display "YO" when the number ``0`` is received
|
||||
by radio.
|
||||
|
||||
```blocks
|
||||
let message = 0;
|
||||
radio.onDataPacketReceived(({ receivedNumber }) => {
|
||||
message = receivedNumber;
|
||||
if (message == 0) {
|
||||
basic.showString("YO")
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
Download the program and **upload the same .hex file to 2 devices!**
|
||||
|
||||
## Step 3
|
||||
|
||||
Use [on button pressed](/reference/input/on-button-pressed) to send the number "1" over radio.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
radio.sendNumber(1);
|
||||
});
|
||||
```
|
||||
|
||||
## Step 4
|
||||
|
||||
Add blocks in [radio on data packet received](/reference/radio/on-data-packet-received) to display "BYE" when the number ``1`` is received
|
||||
by radio.
|
||||
|
||||
```blocks
|
||||
let message = 0;
|
||||
radio.onDataPacketReceived(({ receivedNumber }) => {
|
||||
message = receivedNumber;
|
||||
if (message == 0) {
|
||||
basic.showString("YO")
|
||||
}
|
||||
if (message == 1) {
|
||||
basic.showString("BYE")
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
```package
|
||||
radio
|
||||
```
|
||||
@@ -1,94 +0,0 @@
|
||||
# Challenge
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Welcome! The activity will teach you how to use the acceleration of the 1st @boardname@ and to visualize the acceleration on the 2nd @boardname@.
|
||||
Let's get started!
|
||||
|
||||
### ~
|
||||
Let's measure `acceleration (mg)` and then `send number`. `Acceleration` is measured in **milli-gravities**, so a value of -1000 is equivalent to -1g or -9.81m/s^2. We will be able to get the acceleration value (g-force), in the specified "x" dimension. `Send number` will broadcast a number data packet to other @boardname@s connected via radio.
|
||||
|
||||
```blocks
|
||||
radio.sendNumber(input.acceleration(Dimension.X));
|
||||
```
|
||||
### ~
|
||||
We want to display the acceleration forever. In order to do so, we need a `forever` loop. A forever loop will repeat code in the background forever.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
radio.sendNumber(input.acceleration(Dimension.X));
|
||||
});
|
||||
|
||||
|
||||
```
|
||||
### ~
|
||||
We want to register code to run when a packet is received over radio. We can implement this code by adding `on data received`.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
radio.sendNumber(input.acceleration(Dimension.X))
|
||||
})
|
||||
radio.onDataPacketReceived(() => {
|
||||
|
||||
})
|
||||
```
|
||||
### ~
|
||||
Finally, we want to chart the acceleration. So we must first implement `plot bar graph`. `Plot Bar Graph` will display a vertical bar graph based on the value and high value. In order to transfer the receive the number from the 1st @boardname@, we must implement `receive number` to constantly display a vertical bar graph based on the value. Remember, the value will equal to the @boardname@'s acceleration in the "x" direction.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
radio.sendNumber(input.acceleration(Dimension.X))
|
||||
})
|
||||
radio.onDataPacketReceived(({ receivedNumber }) => {
|
||||
led.plotBarGraph(receivedNumber, 1023)
|
||||
})
|
||||
|
||||
```
|
||||
### ~
|
||||
Notice that moving the @boardname@ the farthest direction in the x direction will be -1023 on the charting beneath the simulator. The second observation will be that the LEDs will be full brightness on the 2nd @boardname@. There is a single LED turned on with the 1st @boardname@. Additionally, the graphs will reflect 0 acceleation for the 1st @boardname@. In this scenario, if you are adjusting the acceleration in the simualator, you are also changing your chart that will be produced.
|
||||
|
||||

|
||||
|
||||
### ~
|
||||
NOTE: The colors of the charts reflect the color of the @boardname@ simulator. In this instance, the @boardname@s are blue and green. So the colors of the line graphs reflect the colors of the @boardname@
|
||||
|
||||
### ~
|
||||
After running this simulation several seconds by moving the @boardname@ side to side in the x direction, you are ready to graph or chart the accceleration of the @boardname@. We want a printout of our acceleration on Excel. We will graph the fluctuating acceleration of the simulation experiment.
|
||||
|
||||

|
||||
|
||||
### ~
|
||||
|
||||
Finally, you must open the Excel CSV file by clicking on the `data.csv` file
|
||||
that was downloaded to Downloads Folder.
|
||||
|
||||

|
||||
|
||||
Use the Recommended Charts command on the Insert tab to quickly create a chart that’s just right for your data.
|
||||
|
||||
* Select the data that you want to include in your chart.
|
||||
|
||||
* Click Insert > Recommended Charts.
|
||||
|
||||

|
||||
|
||||
* On the Recommended Charts tab, scroll through the list of chart types that Excel recommends for your data. Pick the **scatter plot**.
|
||||
|
||||

|
||||
|
||||
* Use the Chart Elements, Chart Styles, and Chart Filters buttons next to the upper-right corner of the chart to add chart elements like axis titles or data labels, to customize the look of your chart
|
||||
|
||||

|
||||
|
||||
### ~
|
||||
Have fun reviewing your simulation and analyze the acceleration by chart the Excel data using Excel.
|
||||
|
||||
* Connect the first @boardname@ to your computer using your USB cable and run the charting script on it.
|
||||
* Connect the second @boardname@ to your computer using your USB cable and run the charting script on it.
|
||||
* The first person and second person take turns tilting the @boardname@ in the "x" direction while the other player charts the data on the @boardname@!
|
||||
* Review and analyze the actual @boardname@ device acceleration data on Excel
|
||||
* Display acceleration with y or z using plot bar graph by changing acceleration from "x" to "y" or "z"
|
||||
|
||||
```package
|
||||
radio
|
||||
```
|
||||
@@ -1,68 +0,0 @@
|
||||
# radio
|
||||
|
||||
Measure the acceleration on the @boardname@ in the "x" direction.
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Welcome! This activity will teach how to use the @boardname@ to chart the acceleration in the "x" direction. Let's get started!
|
||||
|
||||
|
||||
### ~
|
||||
Let's measure `acceleration (mg)` in the "x" direction. Get the acceleration value (milli g-force), in one of three specified dimensions.
|
||||
|
||||
|
||||
```blocks
|
||||
input.acceleration(Dimension.X)
|
||||
```
|
||||
|
||||
### ~
|
||||
Use the plot bar chart to visualize the acceleration on the LED screen of the @boardname@ in the specified range. You implement plot Bar Graph to display a vertical bar graph based on the "value" and "high" value. Then you must insert acceleration in the X dimension to measure the acceleration.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
led.plotBarGraph(input.acceleration(Dimension.X), 0)
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
### ~
|
||||
Notice that moving the @boardname@ in the simulator from left to right (x direction) changes the values beneath the @boardname@ in a range from 1023 to -1023 as measured in milli-gravities. By hovering over the @boardname@ from left to right, you can observe changing values beneath the @boardname@ simulator. Also, the LEDs shown on the Bar Graph fluctates based on the movement of the @boardname@ simulator in the x direction. The line underneath the @boardname@ simulator reflect the acceleration in the x direction.
|
||||
|
||||
NOTE: The colors of the charts reflect the color of the @boardname@ simulator. In this instance, the @boardname@ is yellow. So the color of the data line reflects the color of the @boardname@
|
||||
|
||||

|
||||
|
||||
### ~
|
||||
|
||||
Vigorously move the @boardname@ in the @boardname@ simulatator by moving the @boardname@ image from side to side. Every time the @boardname@ moves in the x direction in the simulator, you are generating data points that can be reviewed in Excel. The more attempts to move the @boardname@ from side to side, the more data being saved in Excel. After you have vigarously moved the @boardname@ simulator from side to side for a sufficient amount of time, you are ready to graph or chart the accceleration of the @boardname@. We want a printout of our acceleration on Excel that can be graphed in Excel.
|
||||
|
||||
### ~
|
||||
|
||||
We want to chart the data collected by using a tool in Excel.
|
||||
|
||||
The final part of this experiment is opening and reviewing the data in the Excel CSV file. Simply click on the line beneath the simulator. A CSV file will be generated to display the data points collected by moving the @boardname@ in the X direction. Then click or tap on the data Excel file that was downloaded to your local ``Downloads`` Folder.
|
||||
|
||||
|
||||
### ~
|
||||
|
||||
|
||||
First, click or tap on the first two columns (A, B) to include the time of the data being collected; b) the results of acceleration data on the @boardname@
|
||||
|
||||

|
||||
|
||||
Use the Recommended Charts command on the Insert tab to quickly create a chart that’s just right for your data.
|
||||
|
||||
* Select the data that you want to include in your chart.
|
||||
|
||||
* Click Insert > Recommended Charts.
|
||||
|
||||

|
||||
|
||||
* On the Recommended Charts tab, scroll through the list of chart types that Excel recommends for your data. Pick the **scatter plot**.
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/projects/radio-challenges)
|
||||
|
||||
### ~
|
||||
|
||||
@@ -1,238 +0,0 @@
|
||||
# rock paper scissors
|
||||
|
||||

|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
```sim
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let img = Math.random(3)
|
||||
if (img == 0) {
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# . . . #
|
||||
# . . . #
|
||||
# . . . #
|
||||
# # # # #
|
||||
`)
|
||||
|
||||
} else if (img == 1) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # # # .
|
||||
. # # # .
|
||||
. # # # .
|
||||
. . . . .
|
||||
`)
|
||||
} else {
|
||||
basic.showLeds(`
|
||||
# # . . #
|
||||
# # . # .
|
||||
. . # . .
|
||||
# # . # .
|
||||
# # . . #
|
||||
`)
|
||||
}
|
||||
})
|
||||
```
|
||||
In this project, you will build a Rock Paper Scissors game with the @boardname@.
|
||||
You can play the game with a friend who has it on a @boardname@.
|
||||
You can also play it with friends who are just using their hands.
|
||||
|
||||
### ~
|
||||
|
||||
|
||||
## Materials needed
|
||||
|
||||
* Your @boardname@ -- that's it!
|
||||
|
||||
## Step 1: Getting started
|
||||
|
||||
We want the @boardname@ to choose rock, paper, or scissors when you shake it.
|
||||
Try creating an ``on shake`` block so when you shake the @boardname@, it will run part of a program.
|
||||
|
||||
```blocks
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
|
||||
})
|
||||
```
|
||||
|
||||
Next, when you shake the @boardname@, it should pick a random number from `0` to `2`
|
||||
and store it in the variable `weapon`. (This variable is named `weapon` because
|
||||
rock, paper, and scissors are the weapons you use to battle your friends!)
|
||||
|
||||
Add a ``set`` block with a variable. Then add a ``pick random`` block,
|
||||
and store the random number in the variable,
|
||||
like this:
|
||||
|
||||
```blocks
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let weapon = Math.random(3)
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
### ~hint
|
||||
No one can predict random numbers. That's what makes them great for Rock Paper Scissors!
|
||||
### ~
|
||||
|
||||
Each possible number these blocks can make (`0`, `1`, or `2`) means a different picture.
|
||||
We will show the right picture for that number on the LED screen.
|
||||
|
||||
|
||||
## Step 2: Picking paper
|
||||
|
||||
Put an ``if`` block after the ``let`` block that checks whether
|
||||
`weapon` is `0`. Make sure the ``if`` block has an ``else if`` part
|
||||
and an ``else`` part.
|
||||
|
||||
Next, add a ``show leds`` block that shows a
|
||||
picture of a piece of paper:
|
||||
|
||||
```blocks
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let weapon = Math.random(3)
|
||||
if (weapon == 0) {
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# . . . #
|
||||
# . . . #
|
||||
# . . . #
|
||||
# # # # #
|
||||
`)
|
||||
} else if (false) {
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
## Step 3: A random rock
|
||||
|
||||
Now we are going to add a new picture for the @boardname@ to show
|
||||
when another random number comes up.
|
||||
|
||||
Make the ``else if`` part check if the variable `weapon` is `1`.
|
||||
Then add a ``show leds`` block with a picture of a rock.
|
||||
|
||||
```blocks
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let weapon = Math.random(3)
|
||||
if (weapon == 0) {
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# . . . #
|
||||
# . . . #
|
||||
# . . . #
|
||||
# # # # #
|
||||
`)
|
||||
|
||||
} else if (weapon == 1) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # # # .
|
||||
. # # # .
|
||||
. # # # .
|
||||
. . . . .
|
||||
`)
|
||||
} else {
|
||||
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
## Step 4: Suddenly scissors
|
||||
|
||||
Add a ``show leds`` block with a picture of scissors to the ``else`` part:
|
||||
|
||||
```blocks
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let weapon = Math.random(3)
|
||||
if (weapon == 0) {
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# . . . #
|
||||
# . . . #
|
||||
# . . . #
|
||||
# # # # #
|
||||
`)
|
||||
|
||||
} else if (weapon == 1) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # # # .
|
||||
. # # # .
|
||||
. # # # .
|
||||
. . . . .
|
||||
`)
|
||||
} else {
|
||||
basic.showLeds(`
|
||||
# # . . #
|
||||
# # . # .
|
||||
. . # . .
|
||||
# # . # .
|
||||
# # . . #
|
||||
`)
|
||||
}
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
### ~hint
|
||||
|
||||
You don't need to check if `weapon` is `2` because `2` is the only number left out of `0`, `1`, and `2`.
|
||||
That's why you can use an ``else`` instead of an ``else if``.
|
||||
|
||||
### ~
|
||||
|
||||
Your game is ready! Have fun!
|
||||
|
||||
## Step 5: Are you the greatest?
|
||||
|
||||
Here is a way you can make your Rock Paper Scissors game better.
|
||||
When button ``A`` is pressed,
|
||||
the @boardname@ will add `1` to your score.
|
||||
|
||||
Open the ``Game`` drawer, and then add the block ``change score by 1`` to your program,
|
||||
like this:
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
game.addScore(1)
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
## Step 6: Prove you're the greatest!
|
||||
|
||||
After your @boardname@ can add `1` to the score, show how many wins you have.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
game.addScore(1)
|
||||
basic.showString("WINS:")
|
||||
basic.showNumber(game.score())
|
||||
})
|
||||
```
|
||||
## Step 7: Staying honest
|
||||
|
||||
Success! Your @boardname@ can track wins!
|
||||
But what about losses?
|
||||
Use the ``Game`` drawer to subtract `1` from your score when you press button `B`.
|
||||
|
||||
Here are all the blocks you will need:
|
||||
|
||||
```shuffle
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
game.addScore(-1)
|
||||
basic.showString("LOSSES:")
|
||||
basic.showNumber(game.score())
|
||||
})
|
||||
```
|
||||
|
||||
## Step 8: Hacking Rock Paper Scissors
|
||||
|
||||
How else can you make your game better?
|
||||
Ever hear of [Rock Paper Scissors Spock Lizard](http://www.samkass.com/theories/RPSSL.html)?
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
# smiley buttons
|
||||
|
||||

|
||||
|
||||
Use buttons to show a smiley or frowny face.
|
||||
|
||||
## Step 1
|
||||
|
||||
Use [show leds](/reference/basic/show-leds) to make a smiley face:
|
||||
|
||||
```blocks
|
||||
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:
|
||||
|
||||
```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(`
|
||||
. # . # .
|
||||
. # . # .
|
||||
. . . . .
|
||||
# . . . #
|
||||
. # # # .`
|
||||
);
|
||||
});
|
||||
```
|
||||
@@ -1,25 +0,0 @@
|
||||
# telegraph activity
|
||||
|
||||

|
||||
|
||||
### ~avatar
|
||||
|
||||
Build a telegraph between two @boardname@s to communicate with your friends!
|
||||
|
||||
### ~
|
||||
|
||||
## Duration: ~30 minutes
|
||||
|
||||
## Materials
|
||||
|
||||
* @boardname@, battery holder and 2 AAA batteries
|
||||
* Crocodile clips
|
||||
|
||||
## Activities
|
||||
|
||||
* [Making the circuit](/projects/telegraph/make)
|
||||
* [Manual telegraph](/projects/telegraph/manual-telegraph)
|
||||
|
||||
### ~button /projects/telegraph/make
|
||||
Let's get started!
|
||||
### ~
|
||||
@@ -1,75 +0,0 @@
|
||||
# telegraph - making
|
||||
|
||||
### ~avatar
|
||||
|
||||
Let's build a telegraph between two @boardname@s.
|
||||
|
||||
### ~
|
||||
|
||||

|
||||
|
||||
## Materials
|
||||
|
||||
* @boardname@, battery holder and 2 AAA batteries
|
||||
* Crocodile clips
|
||||
|
||||
## Steps
|
||||
|
||||
### Step 1
|
||||
|
||||

|
||||
|
||||
Using the 1st crocodile clip, connect the end of the crocodile clip onto GND pin on the @boardname@.
|
||||
|
||||
### Step 2
|
||||
|
||||

|
||||
|
||||
Using the 2nd crocodile clip, connect the end of the crocodile clip onto the 3V pin on the @boardname@.
|
||||
|
||||
### Step 3
|
||||
|
||||

|
||||
|
||||
Using the 3rd crocodile clip, connect the end of the crocodile clip onto pin 1 of the @boardname@.
|
||||
|
||||
### Step 4
|
||||
|
||||

|
||||
|
||||
Using the 4th crocodile clip, connect the end of the crocodile clip onto pin 2 of the @boardname@.
|
||||
|
||||
### Step 5
|
||||
|
||||

|
||||
|
||||
Using the 1st crocodile clip, connect the unattached end of the crocodile clip onto the GND on the 2nd @boardname@.
|
||||
|
||||
### Step 6
|
||||
|
||||

|
||||
|
||||
Using the 2nd crocodile clip, connect the unattached end of the crocodile clip onto the 3V pin on the 2nd @boardname@.
|
||||
|
||||
### Step 7
|
||||
|
||||

|
||||
|
||||
Using the 3rd crocodile clip, connect the unattached end of the crocodile clip onto pin 2 of the 2nd @boardname@.
|
||||
|
||||
### Step 8
|
||||
|
||||

|
||||
|
||||
Using the 4th crocodile clip, connect the unattached end of the crocodile clip onto pin 1 of the 2nd @boardname@
|
||||
|
||||
### Step 9
|
||||
|
||||

|
||||
|
||||
|
||||
### ~button /projects/telegraph/manual-telegraph
|
||||
|
||||
NEXT: manual telegraph
|
||||
|
||||
### ~
|
||||
@@ -1,95 +0,0 @@
|
||||
# telegraph - manual telegraph
|
||||
|
||||
Let's build the code that will send a impulse while the user presses ``A``.
|
||||
|
||||
### Step 1
|
||||
|
||||
We now need to digitally write to pin ``P0`` as **high** (1).
|
||||
|
||||
```blocks
|
||||
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.
|
||||
|
||||
```blocks
|
||||
pins.digitalWritePin(DigitalPin.P0, 1)
|
||||
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:
|
||||
|
||||
```blocks
|
||||
if (input.buttonIsPressed(Button.A)) {
|
||||
pins.digitalWritePin(DigitalPin.P0, 1)
|
||||
led.plot(2, 2)
|
||||
} else { }
|
||||
```
|
||||
|
||||
|
||||
### 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 the LED light.
|
||||
|
||||
```blocks
|
||||
if (input.buttonIsPressed(Button.A)) {
|
||||
pins.digitalWritePin(DigitalPin.P0, 1)
|
||||
led.plot(2, 2)
|
||||
} else {
|
||||
pins.digitalWritePin(DigitalPin.P0, 0)
|
||||
led.unplot(2, 2)
|
||||
}
|
||||
```
|
||||
|
||||
### Step 5
|
||||
|
||||
Let's add a forever loop so this code runs in the background forever. Modify your code so that your code looks like this. Run the code and press Button A.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
if (input.buttonIsPressed(Button.A)) {
|
||||
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(4, 4);
|
||||
}
|
||||
else {
|
||||
led.unplot(4, 4);
|
||||
}
|
||||
basic.forever(() => {
|
||||
if (input.buttonIsPressed(Button.A)) {
|
||||
pins.digitalWritePin(DigitalPin.P0, 1);
|
||||
led.plot(2, 2);
|
||||
}
|
||||
else {
|
||||
pins.digitalWritePin(DigitalPin.P0, 0);
|
||||
basic.clearScreen();
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
Your telegraph is ready!
|
||||
|
||||
### Step 7
|
||||
|
||||
* Connect the first @boardname@ to your computer using your USB cable and put the telegraph script on it.
|
||||
* Connect the second @boardname@ 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!
|
||||
@@ -1,154 +0,0 @@
|
||||

|
||||
|
||||
# the watch
|
||||
|
||||

|
||||
|
||||
In this project, you will build your own wearable @boardname@ watch from an old pair of jeans and T-shirt. Project duration: 15 minutes.
|
||||
|
||||

|
||||
|
||||
## Materials
|
||||
|
||||
* @boardname@, battery holder and 2 AAA batteries
|
||||
* Old T-shirt
|
||||
* Old Jeans
|
||||
* Velcro with sticky back – 5cm x 5cm
|
||||
* Double-sided tape – 22cm x 5cm. You can find carpet tape in your local hardware shop
|
||||
* Ruler and pen
|
||||
* Scissors
|
||||
|
||||

|
||||
|
||||
## Steps
|
||||
|
||||
### Step 1
|
||||
|
||||

|
||||
|
||||
Using the ruler and pen, mark a rectangle of more or less 26cm x 5cm on the T-shirt. Don’t worry if you don’t get it quite right, we’ll tidy things up later on.
|
||||
|
||||
### Step 2
|
||||
|
||||

|
||||
|
||||
Cut the rectangle using the scissors. Don’t worry about the quality of the cut, we’ll trim it later on.
|
||||
|
||||
### Step 3
|
||||
|
||||

|
||||
|
||||
Cut a piece of cloth from the pair of jeans. Cut straight by the seam.
|
||||
|
||||

|
||||
|
||||
### Step 4
|
||||
|
||||

|
||||
|
||||
Using the ruler and pen, mark a rectangle of 22cm x 5cm (adults should use 24cm x 5cm) on the jeans cloth.
|
||||
|
||||
### Step 5
|
||||
|
||||

|
||||
|
||||
Stretch the cloth using your hands and apply the double-side tape on the rectangle marked on the jeans. You might need the help of a friend to achieve this step. Don’t worry if the tape is larger than the rectangle, we will trim it later. Make sure to apply pressure to the tape to secure it firmly.
|
||||
|
||||
### Step 6
|
||||
|
||||

|
||||
|
||||
Using the scissors, cut the rectangle of jeans.
|
||||
|
||||
### Step 7
|
||||
|
||||

|
||||
|
||||
Peal the tape protective layer from the rectangle.
|
||||
|
||||
### Step 8
|
||||
|
||||

|
||||
|
||||
Place the @boardname@ pins on the tape at more or less **7** cm from the left border. Then lower the @boardname@ on the tape and press **gently**.
|
||||
|
||||
### Step 9
|
||||
|
||||

|
||||
|
||||
Connect the battery holder and place it on the right of the @boardname@. Tuck the cables away on the tape to protect them.
|
||||
|
||||
### Step 10
|
||||
|
||||

|
||||
|
||||
Stick the T-shirt rectangle from the top of the @boardname@, over the battery cables.
|
||||
|
||||
### Step 11
|
||||
|
||||

|
||||
|
||||
Use your fingers to push the T-shirt cloth under the @boardname@ to give access to the micro-USB plug.
|
||||
|
||||
### Step 12
|
||||
|
||||

|
||||
|
||||
Place the T-shirt over the battery holder and stick it up to the end.
|
||||
|
||||
### Step 13
|
||||
|
||||

|
||||
|
||||
Turn over the watch and cut the extra T-shirt material.
|
||||
|
||||
### Step 14
|
||||
|
||||

|
||||
|
||||
Stick the T-shirt cloth on the other side of the watch. Lift the @boardname@ pins to slide the cloth under and leave them free from the tape.
|
||||
|
||||
### Step 15
|
||||
|
||||

|
||||
|
||||
Turn over the watch and cut left over T-shirt cloth.
|
||||
|
||||
### Step 16
|
||||
|
||||

|
||||
|
||||
Cut a 5cm x 5cm square of Velcro **loops**.
|
||||
|
||||
### Step 17
|
||||
|
||||

|
||||
|
||||
Cut a 5cm x 5cm square of Velcro **hooks**.
|
||||
|
||||
### Step 18
|
||||
|
||||

|
||||
|
||||
Stick the Velcro hooks on the right side of the battery holder on the T-shirt cloth.
|
||||
|
||||
### Step 19
|
||||
|
||||

|
||||
|
||||
Stick the Velcro loops on the other end on the jeans fabric.
|
||||
|
||||
### Step 20
|
||||
|
||||
Trim any leftover fabric, threads or tape.
|
||||
|
||||
### Step 21
|
||||
|
||||

|
||||
|
||||
Your watch is ready!
|
||||
|
||||
### Acknowledgements
|
||||
|
||||
Artistic design by Melinda Hoeneisen.
|
||||
|
||||
@@ -1,231 +0,0 @@
|
||||
# Timing gates
|
||||
|
||||
### ~avatar
|
||||
|
||||
This project explains the principles of timing gates using household materials.
|
||||
|
||||
### ~
|
||||
|
||||
## Timing gates
|
||||
|
||||
The two gates are connected to the @boardname@ and can detect a car passing through.
|
||||
|
||||

|
||||
|
||||
As the car passes through the gate ``0``, it sends an event to the @boardname@ through the [on pin pressed](/reference/input/on-pin-pressed) block.
|
||||
The @boardname@ records the time in a variable ``t0``.
|
||||
|
||||

|
||||
|
||||
As the car passes through the gate ``1``, it sends an event to the @boardname@ through the [on pin pressed](/reference/input/on-pin-pressed) block.
|
||||
The @boardname@ records the time in a variable ``t1``.
|
||||
|
||||

|
||||
|
||||
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!
|
||||
|
||||

|
||||
|
||||
|
||||
## Materials
|
||||
|
||||
* Carboard
|
||||
* Aluminum fail
|
||||
* Double-side tape (carpet tape)
|
||||
* 4 crocodile clips
|
||||
* A @boardname@ board and USB cable
|
||||
|
||||

|
||||
|
||||
## 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.
|
||||
|
||||

|
||||
|
||||
Lay the Aluminum foil on the double-sided tape. Press firmly on the tape to get a good bonding of the foil.
|
||||
|
||||

|
||||
|
||||
Strip the out foil around and between the tape strips. Make sure both foil strips don't touch each other.
|
||||
|
||||

|
||||
|
||||
Connect a crocodile strip to each foil strip.
|
||||
|
||||

|
||||
|
||||
Connect the crocodile plugs to the ``GND`` and ``P0`` pins on the @boardname@.
|
||||
|
||||

|
||||
|
||||
The gate is ready to use! Your circuit should look like the picture below:
|
||||
|
||||

|
||||
|
||||
|
||||
## Detecting the car with code
|
||||
|
||||
The @boardname@ provides an event [on pin pressed](/reference/input/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.
|
||||
|
||||

|
||||
|
||||
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.
|
||||
|
||||

|
||||
|
||||
Connect the crocodile plugs to the ``GND`` and ``P1`` pins on the @boardname@.
|
||||
|
||||

|
||||
|
||||
## Detecting the second gate
|
||||
|
||||
Since the second gate is connected to pin ``P1``, we add a second [on pin pressed](/reference/input/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 @boardname@ has a clock that measures time precisely. It measures how many seconds the @boardname@ 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!
|
||||
@@ -1,41 +0,0 @@
|
||||
# Wallet
|
||||
|
||||

|
||||
|
||||
### @description A beginner maker activity, building a duct tape wallet with the @boardname@
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Make a @boardname@ wallet with this guided tutorial!
|
||||
|
||||
### ~
|
||||
|
||||

|
||||
|
||||
## Duration
|
||||
|
||||
2 Activities, approx 30-45 min each based on familiarity with the coding concepts
|
||||
|
||||
## Materials
|
||||
|
||||
* Paper sheet
|
||||
* Tape (masking, duct tape, and/or packing tape)
|
||||
* Scissors
|
||||
* 1 @boardname@, battery holder and 2 AAA batteries
|
||||
* Marker or pen
|
||||
|
||||
## Activities
|
||||
|
||||
* [Make](/projects/wallet/make)
|
||||
* [Code](/projects/wallet/code)
|
||||
|
||||
### ~button /projects/wallet/make
|
||||
|
||||
Let's get started!
|
||||
|
||||
### ~
|
||||
|
||||
## References
|
||||
|
||||
The wallet built in this activity is inspired from the duct tape wallet in
|
||||
[A Kid's Guide to Awesome Duct Tape Projects: How to Make Your Own Wallets, Bags, Flowers, Hats, and Much, Much More!](https://www.amazon.com/gp/product/1629148016)
|
||||
@@ -1,59 +0,0 @@
|
||||
# Wallet - Code
|
||||
|
||||
## Simple animation
|
||||
|
||||
Let's start by using a combination of [forever](/reference/basic/forever) and [show leds](/reference/basic/show-leds) to create animation:
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
basic.showLeds(`
|
||||
# # . # #
|
||||
# # . # #
|
||||
. # # # .
|
||||
. # . # .
|
||||
. # . # .
|
||||
`)
|
||||
basic.showLeds(`
|
||||
. . # . .
|
||||
. . # . .
|
||||
# . . . #
|
||||
# . # . #
|
||||
# . # . #
|
||||
`)
|
||||
})
|
||||
```
|
||||
|
||||
Download this code to your @boardname@ and try it out.
|
||||
|
||||
## Turn off animation in the pocket
|
||||
|
||||
If the wallet is in your pocket, you should turn off the LEDs to save energy.
|
||||
|
||||
How do we know that the wallet is in the pocket? It is really dark in there... We can use the [light level](/reference/input/light-level) to detect this!
|
||||
|
||||
Using an [if statement](/blocks/logic/if), we can test if the level of light is sufficient to turn on the screen. Otherwise, we turn off the screen for a few second to save energy.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
if (input.lightLevel() > 16) {
|
||||
basic.showLeds(`
|
||||
# # . # #
|
||||
# # . # #
|
||||
. # # # .
|
||||
. # . # .
|
||||
. # . # .
|
||||
`)
|
||||
basic.showLeds(`
|
||||
. . # . .
|
||||
. . # . .
|
||||
# . . . #
|
||||
# . # . #
|
||||
# . # . #
|
||||
`)
|
||||
} else {
|
||||
// clear screen and wait
|
||||
basic.clearScreen()
|
||||
basic.pause(3000)
|
||||
}
|
||||
})
|
||||
```
|
||||
@@ -1,184 +0,0 @@
|
||||
# Wallet - Make
|
||||
|
||||
### @description Maker Project for Wallet
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Make the duct tape wallet for your @boardname@
|
||||
|
||||
### ~
|
||||
|
||||
## Duration: ~30 minutes
|
||||
|
||||
## Materials
|
||||
* Paper sheet
|
||||
* Tape (masking, duct tape, and/or packing tape)
|
||||
* Scissors
|
||||
* 1 @boardname@, battery holder and 2 AAA batteries
|
||||
* Marker or pen
|
||||
|
||||

|
||||
|
||||
|
||||
## Duct tape sheet
|
||||
|
||||
Let's start by building a duct tape sheet.
|
||||
|
||||
Position the paper sheet on the workbench and place lines of tape over it. Make sure to overlap each layer to avoid seeing gaps of papers. In case of mistake, add tape!
|
||||
|
||||

|
||||
|
||||
Cover the entire paper sheet with tape. Don't hesitate to use various colors or patterns!
|
||||
|
||||

|
||||
|
||||
Unstick the sheet from the workbench carefully to avoid ripping out the tape and turn it over.
|
||||
|
||||

|
||||
|
||||
Fold the remaining tape sections on the sides towards the center.
|
||||
|
||||

|
||||
|
||||
Great job, your duct tape sheet is ready! Let's get onto the next step.
|
||||
|
||||

|
||||
|
||||
## Card Hole
|
||||
|
||||
We need to cut a hole in the center of the sheet to allow storage of coins and cards inside the wallet.
|
||||
|
||||
|
||||
Gently fold the sheet in half.
|
||||
|
||||

|
||||
|
||||
Gently foldy the other way.
|
||||
|
||||

|
||||
|
||||
Place the duct tape roll on the inside corner. This will determine the size of the hole.
|
||||
|
||||

|
||||
|
||||
Use your marker and trace around the roll.
|
||||
|
||||

|
||||
|
||||
Use your scissors and cut along the line you've just traced while keeping the sheet folded.
|
||||
|
||||

|
||||
|
||||
Well done! The hole is done and perfectly centered!
|
||||
|
||||

|
||||
|
||||
## Mounting the @boardname@
|
||||
|
||||
We are going to cut a hole for the @boardname@ screen and buttons on the front of the wallet.
|
||||
|
||||
Place the @boardname@ on the back of the sheet.
|
||||
|
||||

|
||||
|
||||
Mark the contour of the @boardname@ on the sheet with your marker. Don't worry about little mistakes.
|
||||
|
||||

|
||||
|
||||
Mark ticks at the location of each corners of the screen as shown on the picture.
|
||||
|
||||

|
||||
|
||||
Use the @boardname@ as a ruler to trace a line between the ticks.
|
||||
|
||||

|
||||
|
||||
Fill the inside square with your marker, you will need to cut it out later.
|
||||
|
||||

|
||||
|
||||
Mark the ticks along the button using the same procedure.
|
||||
|
||||

|
||||
|
||||
Fill the button square as well so that you clearly know what to cut or not.
|
||||
|
||||

|
||||
|
||||
Fold the sheet over the center of the darken area and cut out a triangle large enough to squeeze a blade of the scissors.
|
||||
|
||||

|
||||
|
||||
Starting from the small hole, work your way through cutting out the darkened area.
|
||||
|
||||

|
||||
|
||||
Eventually, the opening should look like a rectangle with a square in the middle.
|
||||
|
||||

|
||||
|
||||
Try mounting the @boardname@ and cutting more material as needed.
|
||||
|
||||

|
||||
|
||||
Put a generous layer of tape on the back of the @boardname@ to stick it on the wallet.
|
||||
|
||||

|
||||
|
||||
Attach the battery to the @boardname@. You are done for this step!
|
||||
|
||||

|
||||
|
||||
## Folding
|
||||
|
||||
The last step is to fold the sheet and tape the sides to get a wallet.
|
||||
|
||||
Start form the sheet facing paper up and fold the sheet over the large hole in the center.
|
||||
|
||||

|
||||
|
||||
Fold another time until the large hole is visible.
|
||||
|
||||

|
||||
|
||||
Apply a layer of tape on the side with the tape overlapping half over the wallet.
|
||||
|
||||

|
||||
|
||||
Flip over the wallet carefully.
|
||||
|
||||

|
||||
|
||||
Fold the remaining tape over the wallet and cut the sides with the scissors.
|
||||
|
||||

|
||||
|
||||
Tuck in the battery in the pocket inside the wallet and make sure the cables are out of the way.
|
||||
|
||||

|
||||
|
||||
Apply the tape on the side using the same procedure.
|
||||
|
||||

|
||||
|
||||
That's it! You have an @boardname@ wallet!
|
||||
|
||||

|
||||
|
||||
## Protecting those buttons!
|
||||
|
||||
The buttons of the @boarname@ are left vulnerable to being ripped out.
|
||||
|
||||

|
||||
|
||||
If you plan to make an extensive use of your wallet without using the buttons, you might want to consider to protect the buttons with additional tape.
|
||||
|
||||

|
||||
|
||||
The wallet is ready, we just have to add some code into the @boardname@ to make it alive.
|
||||
|
||||
### ~button /projects/wallet/code
|
||||
|
||||
Let's add some code!
|
||||
|
||||
### ~
|
||||
Reference in New Issue
Block a user