Example Code for Arduino-Fade In Out
In this section, we'll tell you how to use the LED module Control a String Light to fade in and out
Hardware Preparation
- DFRduino UNO (or similar) x 1
- LED String x 1
- M-M/F-M/F-F Jumper wires
Software Preparation
Wiring Diagram
Sample Code
/***************************************************
* LED String Lights
* ****************************************************
* Control a String Light to fade in and out
* @author Dongzi([email protected])
* @version V1.0
* @date 2016-5-26
* All above must be included in any redistribution
* ****************************************************/
int t;
#define Light_string 3
void setup() {
pinMode( Light_string, OUTPUT);
}
void loop() {
for(t=5;t<255;t++ ) // turn the Light string on (HIGH is the voltage level) little and little.
{
analogWrite( Light_string, t);
delay(10);
}
if(t>=255) // turn the Light string off (HIGH is the voltage level) little and little.
{
for(t==255;t>5;t--)
{
analogWrite( Light_string, t);
delay(10);
}
}
}
Was this article helpful?
