ButtoncontrolLED

In this example, we will use a push-button to control the LED.

The input signal will change as you press the button. Thus, you can set LED status according to different input states.

What you need

  • SwiftIO board

  • Button

  • Jumper wires

Kits that meet the experimental conditions:

Circuit

There is an onboard RGB LED. Please apply low voltage to light it.

The button has four legs. The two legs on same side are interconnected.

  • Connect the leg on left side to 3.3V pin.

  • Connect the leg on right side to digital pin D10.

In default mode, the digital pin reads false. When you press the button, the two points on the button will be connected. And the value of pin will be true.

So please be sure you connected the button in a right way.

Code

Here comes the code. You can find the example code at the bottom left corner of IDE: > SimpleIO > ButtoncontrolLED.

Instruction

DigitalIn class is intended to detect the state of a digital input pin. The input value is either true(1) or false(0). The .read() function reads the value from a digital input pin.

If you have the experience with Arduino, you may notice there's no pull-down resistor on the button. That's because the SwiftIO Board already provides a pull-down function. Reference the DigitalIn class for more information.

See Also

Last updated