ReadDigitalInput
Last updated
Was this helpful?
Last updated
Was this helpful?
In this example, let's try to read digital signal using a pushbutton. The input value is true or false. Here you will use serial monitor to show the it.
SwiftIO board
Button
Jumper wires
The button has four legs. The two legs on same side are shorted.
Connect one leg on the left side to 3.3 pin. And 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.
The parameter passed by the object DigitalIn
must be the ports (D0-D45) that can be used for digital input in the enumeration Id
. The return value is true
or false
, representing high level and low level respectively.
The print()
function is to print the result directly to the serial port. You can conveniently use a computer to connect to the serial port of the SwiftIO Board to view the results and debug.
You can find the example code at the bottom left corner of IDE: > GettingStarted > ReadDigitalInput.
Please note that the SwiftIO Board has two USB ports. The port used to load programs cannot be used as a monitor serial port, so you need to change the line. For details, please see the operations below. Both USB ports can be used as power supply ports for SwiftIO Board.
​ - Enumerations of all pins on the board.
​ - Detect the state of a digital input pin. The input value is either true (1) or false (0).