pxt-calliope/docs/projects/smiley-buttons.md
Sam El-Husseini 2e9cb3c43b
Fix tutorial authoring for getting started (#885)
* Fix tutorial authoring for getting started

Remove extra new lines

* Fix other tutorials
2018-06-21 16:02:19 -07: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.

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

Step 3

Click |Download| to transfer your code in your @boardname@ and try pressing button A.

Step 4

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 5

Click |Download| to transfer your code in your @boardname@ and try pressing button A or B.

Step 6

Add a secret mode where 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 7

Click |Download| to transfer your code in your @boardname@ and show it off to your friends!