The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
Arduino RGB LED Fade
Posted by: Jon Mulligan | May 8, 2010 @ 3:52pm
C Code
[
Download
]
int ledPinb = 11; // Blue LED connected to digital pin 11 int ledPing = 10 // Green LED connected to digital pin 10 int ledPinr = 9; // Red LED connected to digital pin 9 void setup() { // nothing happens in setup } void loop() { // Green to Blue for(int fadeValueb = 0, fadeValueg = 255, fadeValuer =0; fadeValueb <= 255, fadeValueg >= 0; fadeValueb +=5, fadeValueg -=5){ // sets the value (range from 0 to 255): analogWrite(ledPinb, fadeValueb); analogWrite(ledPing, fadeValueg); analogWrite(ledPinr, fadeValuer); //30 milliseconds to see the dimming effect delay(30); } // Blue to Red for(int fadeValueg = 0, fadeValueb = 255, fadeValuer = 0; fadeValueg <= 0, fadeValueb >= 0, fadeValuer <= 255; fadeValueg +=0, fadeValueb -=5, fadeValuer +=5){ // sets the value (range from 0 to 255): analogWrite(ledPing, fadeValueg); analogWrite(ledPinb, fadeValueb); analogWrite(ledPinr, fadeValuer); //30 milliseconds to see the dimming effect delay(30); } // Red to Green for(int fadeValueg = 0, fadeValueb = 0, fadeValuer = 255; fadeValueg <= 0, fadeValueb >= 0, fadeValuer >= 0; fadeValueg +=5, fadeValueb -=0, fadeValuer -=5){ // sets the value (range from 0 to 255): analogWrite(ledPing, fadeValueg); analogWrite(ledPinb, fadeValueb); analogWrite(ledPinr, fadeValuer); //30 milliseconds to see the dimming effect delay(30); } } // Based on the arduino source code // Modified by Jon Mulligan
Syntax Highlighting
[
Open in new window
]
Author Comments
This code allows 3 leds (red, green, blue) to cycle through the
spectrum.
Rating
4.77 / 8
73 Votes