EasyManua.ls Logo

SunFounder 3in1 Kit - Digital Write

Default Icon
351 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
CHAPTER
FOUR
BASIC PROJECTS
This chapter is used to learn how to control electronic circuits using Arduino.
Depending on the components, the basic control methods of Arduino can be divided into four types:
1. Digital Write: Set the output voltage of the pin to be high or low, which can be used to turn the light on and
off.
2. Analog Write: Write the analog value (PWM wave) to the pin, which can be used to adjust the brightness of
the light.
3. Digital Read: Read the level signal of the digital pin, which can be used to read the working condition of the
switch.
4. Analog Read: Read the voltage of the analog pin, which can be used to read the working condition of the
knob.
There are also some components that require additional libraries for use, and these are grouped under the section 5.11
Install External Libraries.
Finally, the kit also provides some 6. Funny Project, which includes many simple and useful manipulations. Try this
section of code and you will understand how most simple projects work.
4.1 1. Digital Write
Digital Write is to output or write a digital signal to a digital pin. The digital signal has only two states, 0 or 1, 0V or
5V, so it allows some components, such as the LED and buzzer, to be on or off.
On the Arduino R4 board, there are 14 digital I/0 pins from 0 to 13, now use the pinMode() and digitalWrite()
functions to write a high or low level to these digital pins.
pinMode(pin, mode): Configure the specific pin as INPUT or OUTPUT, here it needs to be set as OUTPUT.
Syntax
pinMode(pin, mode)
Parameters
pin: the Arduino pin number to set the mode of.
mode: INPUT, OUTPUT, or INPUT_PULLUP.
digitalWrite(pin, value): Write a high level (5V) or a low level (0V) to a digital pin to change the operating
state of the component. If the pin has been configured as an OUTPUT with pinMode(), its voltage will be set to
the corresponding value: 5V (or 3.3V on 3.3V boards) for HIGH, 0V (ground) for LOW.
Syntax
digitalWrite(pin, value)
87

Related product manuals