pxt-calliope/docs/projects/smiley-buttons.md
Galen Nickel f4aa25e2bd Modify tutorials for single download step (#1093)
* Modify tutorials for single dl step

* Some more fixes

* coin flip typer
2018-08-17 10:58:45 -04:00

1.6 KiB

Smiley Buttons

Step 1

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

input.onButtonPressed(Button.A, () => { 
});

Step 2

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.onButtonPressed(Button.A, () => { 
    basic.showLeds(`
        # # . # #
        # # . # #
        . . . . .
        # . . . #
        . # # # .`
        );
});

Step 3

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

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

Step 4

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

input.onButtonPressed(Button.AB, () => {
    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!