Curriculum
Course: Push Button With Led
Login
Text lesson

MBlock Coding

mBlock Coding

Step 1 – Create Variable

Create a variable called:

 
buttonState
 

This variable stores whether the button is pressed or not.


Step 2 – mBlock Logic

When Arduino Starts Up

Forever

    set buttonState to read digital pin 2

    if buttonState = LOW then

        set pin 13 HIGH

    else

        set pin 13 LOW

 

mBlock Style

 

When Arduino Starts Up

Forever

set buttonState to read pin 2

if buttonState = 1 then

Set Pin 13 HIGH

Else

Set Pin 13 LOW
×
×

Cart