Grove Beginners kit: Arduino Lesson 2 Press Button
This extends the previous lesson by adding a button to control the LED’s state.
|The Grove Beginner Kit For Arduino includes an Arduino Uno board with preconnected devices. The Grove lessons supporting this present coding using the Arduino IDE. These pages present the same lessons using the Codecraft IDE that uses the Block style of coding with specific Grove Arduino blocks.|
A button as a digital input can be used to control a digital output to an LED.
the input of the button is a digital signal, and so there are only two states, 0 or 1, OFF OR ON. So it can control the output to the LED by setting it to the same state as input.
Grove Beginners Kit
Components this lesson
- Grove LED
- Grove Button
|Component||Interface||Type||Pins or Address|
|AirPressureSensor BMP280||I2C||sensor||I2C 0x77(default)/0x76(optional)|
For these lessons, the Components are already connected through the board. That is, for this lesson, LED module is already connected to D4 on the microprocessor.
The lesson code block.
The input D6 and output D4 are automatically set to input and output. No coding needed.
IF D6 is Hi (Button is pressed)
- THEN Set D4 to Hi and so turn the LED on
- ELSE Clear D4 and so turn LED off
Loop means that this part gets continuously repeated.
How to create this ...
Watch the video on Youtube:
For this lesson, Press the button and the LED should light; and go off when released.
A short delay is added to each loop so that the microprocessor isn’t always busy doing nothing.
|This Category Links|
|Category:||Arduino Beginners Index:||Arduino Beginners|
|Next: >||Grove Beginners kit||Arduino Lesson 3 Rotary dial controlling the Blink Frequency|
|< Prev:||Grove Beginners kit||Arduino Lesson 1b Download program to board|