[Arduino] Make Full color LED Lamps bright
Document :
This Full color LED Lamps is common anode.
The pin number 1 of Full color LED Lamp connect to Digital pin ~3.( ~3 mean can do fade function)
The pin number 2 of Full color LED Lamp connect to Digital pin ~5.
The pin number 4 of Full color LED Lamp connect to Digital pin ~6.
#########################################################
/*
Fade
This example shows how to fade an LED on pin 9
using the analogWrite() function.
This example code is in the public domain.
*/
int led3 =3; // the pin that the LED is attached to
int led6 = 6; // the pin that the LED is attached to
int led9 = 9; // the pin that the LED is attached to
int brightness = 1; // how bright the LED is
int fadeAmount = 1; // how many points to fade the LED by
// the setup routine runs once when you press reset:
void setup() {
// declare pin 9 to be an output:
pinMode(led3, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(led9, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// set the brightness of pin 9:
analogWrite(led3, brightness );
analogWrite(led6, brightness % 10);
analogWrite(led9, brightness % 20);
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness == 0 || brightness == 10) {
fadeAmount = -fadeAmount ;
}
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
0 意見:
張貼留言