pxt-calliope/docs/projects/smiley-buttons.md
2016-10-13 11:32:25 -07:00

1.2 KiB

smiley buttons

Use buttons to show a smiley or frowny face.

Step 1

Use show leds to make a smiley face:

basic.showLeds(`
    . # . # .
    . # . # .
    . . . . .
    # . . . #
    . # # # .`
    );

Step 2

Add an input block for when button A is pressed, and put a frowny face inside it:

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

Step 3

Now add blocks so that when button B is pressed, a smiley appears:

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