pxt-calliope/docs/projects/smiley-buttons.md
Juri Wolf a93febb5b7
Map and clean deprecated functions (#175)
* add image and deprecated arrow functions

* update locales

* map basic.showArrow

* map arrow blocks

* map & remove arrow images

* remove arrow blocks

* update locales

* remove & patch:
rgbw -> rgb
button/pin pressed -> button/pin event
loudness -> soundLevel

* update ts mappings for arrows

* add wip ts patch rules

* update .blocks files

* use Click instead of Down as default in Documentation and tests

* patch test.blocks

* fix lowercase name tag

* update test.blocks

* update blocks test files

* update blocks test files

* format block files

* pass blocks file tests

* fix ts mapping

* fix color.defl value

closes https://github.com/microsoft/pxt-calliope/issues/136

* fix ts mappings

- add optional spacing at the end of rgbw()
- map up to v4.0.19

* add suggested changes

* replace innerText by textContent

Co-authored-by: JW <gitkraken@juriwolf.de>
Co-authored-by: Juri <info@juriwolf.de>
2022-04-26 10:28:42 -07:00

1.9 KiB

Smiley Buttons

Introduction @unplugged

Code the buttons on the @boardname@ to show that it's happy or sad. (Want to learn how the buttons works? Watch this video).

Pressing the A and B buttons

Step 1 @fullscreen

Place a ||input:on button pressed|| block to run code when button A is pressed.

input.onButtonEvent(Button.A, ButtonEvent.Click, () => { 
});

Step 2 @fullscreen

Place a ||basic:show leds|| block inside ||input:on button pressed|| to display a smiley on the screen. Press the A button in the simulator to see the smiley.

input.onButtonEvent(Button.A, ButtonEvent.Click, () => { 
    basic.showLeds(`
        # # . # #
        # # . # #
        . . . . .
        # . . . #
        . # # # .`
        );
});

Step 3 @fullscreen

Add ||input:on button pressed|| and ||basic:show leds|| blocks to display a frowny when button B is pressed.

input.onButtonEvent(Button.B, ButtonEvent.Click, () => { 
    basic.showLeds(`
        # # . # #
        # # . # #
        . . . . .
        . # # # .
        # . . . #`
        );
});

Step 4 @fullscreen

Add a secret mode that happens when A and B are pressed together. For this case, add multiple ||basic:show leds|| blocks to create an animation.

input.onButtonEvent(Button.AB, ButtonEvent.Click, () => {
    basic.showLeds(`
        . . . . .
        # . # . .
        . . . . .
        # . . . #
        . # # # .
        `)
    basic.showLeds(`
        . . . . .
        . . # . #
        . . . . .
        # . . . #
        . # # # .
        `)    
})

Step 5

If you have a @boardname@, connect it to USB and click |Download| to transfer your code. Press button A on your @boardname@. Try button B and then A and B together.

Step 6

Nice! Now go and show it off to your friends!