Skip to content

Commit

Permalink
update function parm syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
ganicke committed Jul 19, 2024
1 parent 8c5ac19 commit f419496
Show file tree
Hide file tree
Showing 49 changed files with 502 additions and 502 deletions.
2 changes: 1 addition & 1 deletion docs/projects/analog-pin-tester.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Press ``A`` to scroll the value on the screen.

```blocks
let reading = 0
basic.forever(() => {
basic.forever(function () {
reading = pins.analogReadPin(AnalogPin.P0)
led.plotBarGraph(
reading,
Expand Down
50 changes: 25 additions & 25 deletions docs/projects/banana-keyboard/code.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,43 @@ Have you ever tried making beat box sounds? Let's try making a beatbox with code
Start by adding a variable to store a musical note. Rename the variable to `sound`. Set the value of the variable to the note block `Middle A` from the **Music** drawer.

```blocks
let sound = music.noteFrequency(Note.A);
let sound = music.noteFrequency(Note.A)
```

We want to play music when the fruit connected to a pin pressed. So, we register an event handler that executes whenever pin **1** is pressed. Pin **1** is, of course, connected to the banana. Add a ``||input:on pin pressed||`` block from the **Input** drawer.

```blocks
let sound = music.noteFrequency(Note.A);
input.onPinPressed(TouchPin.P1, () => {
let sound = music.noteFrequency(Note.A)
input.onPinPressed(TouchPin.P1, function () {
})
```

Now, let's create some notes to play when the banana is pressed. Click on the **Loops** drawer then insert a ``||loops:repeat||`` loop into the ``||input:on pin pressed||`` block. Click on the **Variables** drawer and pull out a ``||variables:change item by||`` block and put it into the loop. Rename the variable to `sound`. Change the value from `1` to `25`. This will increase the variable `sound` from the note frequency of block `Middle A` to `Middle A` plus 25 and so on. Put a ``||variables:set to||`` block for `sound` right after the loop. Set it to `Middle A` in order to reset the sound after a banana press.

```blocks
let sound = music.noteFrequency(Note.A);
let sound = music.noteFrequency(Note.A)
input.onPinPressed(TouchPin.P1, () => {
input.onPinPressed(TouchPin.P1, function () {
for (let i = 0; i < 4; i++) {
sound += 25;
sound += 25
}
sound = music.noteFrequency(Note.A);
});
sound = music.noteFrequency(Note.A)
})
```

Finally, insert a ``||music:play tone||`` above the ``||variables:change by||``. Pull out the ``sound`` variable block and drop it in the note slot of ``||music:play tone||``. Change the beat fraction from `1` to `1/4`.

```blocks
let sound = music.noteFrequency(Note.A);
let sound = music.noteFrequency(Note.A)
input.onPinPressed(TouchPin.P1, () => {
input.onPinPressed(TouchPin.P1, function () {
for (let i = 0; i < 4; i++) {
music.playTone(sound, music.beat(BeatFraction.Quarter));
sound += 25;
music.playTone(sound, music.beat(BeatFraction.Quarter))
sound += 25
}
sound = music.noteFrequency(Note.A);
});
sound = music.noteFrequency(Note.A)
})
```

Click `|Download|` and try a banana press. Did you hear 4 notes play?
Expand All @@ -55,23 +55,23 @@ Go back to **[Make](/projects/banana-keyboard/make)** and repeat steps 7 and 8 w
Duplicate the ``||input:on pin pressed||`` event handler to make a second one. For the new ``||input:on pin pressed||``, change the pin name to **P2**. In the pin **P2** event, let's have the the frequency in the variable `sound` decrease by 25 instead of having it increase. Change the `25` in the ``||variables:change by||`` block to `-25`. OK, your code now looks like this:

```blocks
let sound = music.noteFrequency(Note.A);
let sound = music.noteFrequency(Note.A)
input.onPinPressed(TouchPin.P1, () => {
input.onPinPressed(TouchPin.P1, function () {
for (let i = 0; i < 4; i++) {
music.playTone(sound, music.beat(BeatFraction.Quarter));
sound += 25;
music.playTone(sound, music.beat(BeatFraction.Quarter))
sound += 25
}
sound = music.noteFrequency(Note.A);
});
sound = music.noteFrequency(Note.A)
})
input.onPinPressed(TouchPin.P2, () => {
input.onPinPressed(TouchPin.P2, function () {
for (let i = 0; i < 4; i++) {
music.playTone(sound, music.beat(BeatFraction.Quarter));
sound += -25;
music.playTone(sound, music.beat(BeatFraction.Quarter))
sound += -25
}
sound = music.noteFrequency(Note.A);
});
sound = music.noteFrequency(Note.A)
})
```

Click `|Download|` again and play both bananas. It's a fruit jam session!
2 changes: 1 addition & 1 deletion docs/projects/banana-keyboard/make.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Your banana keyboard is ready!

Connect your @boardname@ to your computer using your USB cable and run this script:
```blocks
input.onPinPressed(TouchPin.P1, () => {
input.onPinPressed(TouchPin.P1, function () {
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quarter));
});
```
Expand Down
24 changes: 12 additions & 12 deletions docs/projects/crashy-bird.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ Before creating the code for the game actions, let's first add some controls so
```blocks
let bird: game.LedSprite = null
input.onButtonPressed(Button.A, () => {
input.onButtonPressed(Button.A, function () {
bird.change(LedSpriteProperty.Y, -1)
})
input.onButtonPressed(Button.B, () => {
input.onButtonPressed(Button.B, function () {
bird.change(LedSpriteProperty.Y, 1)
})
```
Expand Down Expand Up @@ -79,11 +79,11 @@ for (let index = 0; index <= 4; index++) {
}
}
input.onButtonPressed(Button.A, () => {
input.onButtonPressed(Button.A, function () {
bird.change(LedSpriteProperty.Y, -1)
})
input.onButtonPressed(Button.B, () => {
input.onButtonPressed(Button.B, function () {
bird.change(LedSpriteProperty.Y, 1)
})
```
Expand All @@ -97,7 +97,7 @@ Right click on the ``||value||`` block and rename it to ``||obstacle||``
```blocks
let obstacles: game.LedSprite[] = []
basic.forever(() => {
basic.forever(function () {
for (let obstacle of obstacles) {
obstacle.change(LedSpriteProperty.X, -1)
}
Expand All @@ -114,7 +114,7 @@ Make obstacles disappear after reaching leftmost corner. Iterate over all obstac
```blocks
let obstacles: game.LedSprite[] = []
basic.forever(() => {
basic.forever(function () {
while (obstacles.length > 0 && obstacles[0].get(LedSpriteProperty.X) == 0) {
obstacles.removeAt(0).delete()
}
Expand All @@ -134,7 +134,7 @@ At the moment, our code generates just one vertical obstacle. We need to put obs
let emptyObstacleY = 0
let obstacles: game.LedSprite[] = []
basic.forever(() => {
basic.forever(function () {
while (obstacles.length > 0 && obstacles[0].get(LedSpriteProperty.X) == 0) {
obstacles.removeAt(0).delete()
}
Expand All @@ -159,7 +159,7 @@ let ticks = 0
let emptyObstacleY = 0
let obstacles: game.LedSprite[] = []
basic.forever(() => {
basic.forever(function () {
while (obstacles.length > 0 && obstacles[0].get(LedSpriteProperty.X) == 0) {
obstacles.removeAt(0).delete()
}
Expand Down Expand Up @@ -190,7 +190,7 @@ let ticks = 0
let emptyObstacleY = 0
let obstacles: game.LedSprite[] = []
basic.forever(() => {
basic.forever(function () {
while (obstacles.length > 0 && obstacles[0].get(LedSpriteProperty.X) == 0) {
obstacles.removeAt(0).delete()
}
Expand Down Expand Up @@ -226,17 +226,17 @@ let emptyObstacleY = 0
let obstacles: game.LedSprite[] = []
let index = 0
let bird: game.LedSprite = null
input.onButtonPressed(Button.A, () => {
input.onButtonPressed(Button.A, function () {
bird.change(LedSpriteProperty.Y, -1)
})
input.onButtonPressed(Button.B, () => {
input.onButtonPressed(Button.B, function () {
bird.change(LedSpriteProperty.Y, 1)
})
index = 0
obstacles = []
bird = game.createSprite(0, 2)
bird.set(LedSpriteProperty.Blink, 300)
basic.forever(() => {
basic.forever(function () {
while (obstacles.length > 0 && obstacles[0].get(LedSpriteProperty.X) == 0) {
obstacles.removeAt(0).delete()
}
Expand Down
6 changes: 3 additions & 3 deletions docs/projects/fireflies.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ When the clock reaches "noon" (let's pick `8` as noon), we turn on the screen br
```block
// the clock ticker
let clock = 0
basic.forever(() => {
basic.forever(function () {
// if clock "hits noon", flash the screen
if (clock >= 8) {
// flash
Expand All @@ -61,7 +61,7 @@ When a firefly flashes, it also sends a number over radio using ``||radio:radio
```block
// the clock ticker
let clock = 0
basic.forever(() => {
basic.forever(function () {
// if clock "hits noon", flash the screen
if (clock >= 8) {
// notify neighbors
Expand Down Expand Up @@ -111,7 +111,7 @@ radio.onReceivedNumber(function (receivedNumber) {
// advance clock to catch up neighbors
clock += 1
})
basic.forever(() => {
basic.forever(function () {
// if clock hits noon, flash the screen
if (clock >= 8) {
// notify neighbors
Expand Down
10 changes: 5 additions & 5 deletions docs/projects/guitar/accelerometer.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ acceleration of gravity.

## Step 1: Graphing acceleration
```blocks
basic.forever(() => {
basic.forever(function () {
led.plotBarGraph(input.acceleration(Dimension.Y), 1023)
})
```
Expand All @@ -76,11 +76,11 @@ Try graphing the acceleration along the **X** and **Z** axis. Can you explain th
## 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(() => {
basic.forever(function () {
music.setTempo(pins.map(Math.abs(input.acceleration(Dimension.Y)),
0, 1023,
60, 320))
music.playTone(Note.C, music.beat(BeatFraction.Quarter));
music.playTone(Note.C, music.beat(BeatFraction.Quarter))
})
```

Expand All @@ -94,14 +94,14 @@ basic.forever(() => {
**Put it all together!**

```blocks
basic.forever(() => {
basic.forever(function () {
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**
Expand Down
14 changes: 7 additions & 7 deletions docs/projects/guitar/displaybuttons.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Headphones
. # . # .
. # # # .
`);
input.onButtonPressed(Button.A, () => {});
input.onButtonPressed(Button.A, function () {})
music.playTone(Note.C, music.beat(BeatFraction.Quarter))
music.rest(music.beat(BeatFraction.Whole))
music.beat(BeatFraction.Quarter)
Expand All @@ -52,7 +52,7 @@ Open @homeurl@ in your web browser
. # # # .
. # . # .
. # # # .
`);
`)
```
From **Basics**, drag a **show LEDs** block into the coding area
* Create a face with LEDs
Expand All @@ -63,7 +63,7 @@ Follow the instructions to move the code to your @boardname@.

## Step 2: Add Smiley LED Button Events
```blocks
input.onButtonPressed(Button.A, () => {
input.onButtonPressed(Button.A, function () {
basic.showLeds(`
. # . # .
. . . . .
Expand All @@ -72,7 +72,7 @@ input.onButtonPressed(Button.A, () => {
. # # # .
`)
})
input.onButtonPressed(Button.B, () => {
input.onButtonPressed(Button.B, function () {
basic.showLeds(`
. # . # .
. . . . .
Expand Down Expand Up @@ -115,7 +115,7 @@ Connect the headphones with crocodile clips
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, () => {
input.onButtonPressed(Button.A, function () {
music.playTone(Note.C, music.beat(BeatFraction.Quarter))
music.rest(music.beat(BeatFraction.Whole))
music.playTone(Note.C, music.beat(BeatFraction.Quarter))
Expand All @@ -133,7 +133,7 @@ input.onButtonPressed(Button.A, () => {
## ~
## Step 4: Add Tone Playing Events for Buttons A & B
```blocks
input.onButtonPressed(Button.A, () => {
input.onButtonPressed(Button.A, function () {
basic.showLeds(`
. # . # .
. . . . .
Expand All @@ -143,7 +143,7 @@ input.onButtonPressed(Button.A, () => {
`)
music.playTone(Note.A, music.beat(BeatFraction.Whole))
})
input.onButtonPressed(Button.B, () => {
input.onButtonPressed(Button.B, function () {
basic.showLeds(`
. # . # .
. . . . .
Expand Down
8 changes: 4 additions & 4 deletions docs/projects/guitar/lightsensor.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ The forever loop really does run forever. The forever loop is useful when there
## Blocks

```cards
basic.forever(() => {})
basic.forever(function () {})
input.lightLevel()
led.plotBarGraph(0, 255)
music.playTone(Note.C, music.beat(BeatFraction.Quarter))
```

## Step 1: Create a light level detector
```blocks
basic.forever(() => {
basic.forever(function () {
led.plotBarGraph(input.lightLevel(), 255)
})
```
Expand Down Expand Up @@ -80,7 +80,7 @@ music.playTone(261, music.beat(BeatFraction.Half))

## Step 3: Multiply Frequency using Math blocks
```blocks
input.onButtonPressed(Button.A, () => {
input.onButtonPressed(Button.A, function () {
music.playTone(261 * 2, music.beat(BeatFraction.Half))
})
```
Expand All @@ -95,7 +95,7 @@ Create a **play tone** block using a **Math** section, **multiplication** block

## Step 4: Control the Frequency with the light input
```blocks
basic.forever(() => {
basic.forever(function () {
music.playTone(input.lightLevel() * 25, music.beat(BeatFraction.Quarter))
})
```
Expand Down
Loading

0 comments on commit f419496

Please sign in to comment.