Last active
September 16, 2019 09:54
-
-
Save teos0009/051476766151d0791bc0d83da45ba729 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Arduino RGB Fading for Common Anode Rgb Leds code from public domain https://github.com/Make-Magazine/UMP-Sample-Code/blob/master/rgb_led_lamp/rgb_led_lamp.ino | |
const int redPin = 1; | |
const int grnPin = 2; | |
const int bluPin = 3; | |
// Setup for outputs | |
void setup() | |
{ | |
pinMode(redPin, OUTPUT); | |
pinMode(grnPin, OUTPUT); | |
pinMode(bluPin, OUTPUT); | |
} | |
// Loop for fading | |
void loop() { | |
redtoyellow(); | |
yellowtogreen(); | |
greentocyan(); | |
cyantoblue(); | |
bluetomagenta(); | |
magentatored(); | |
} | |
// Functions for fade between 2 colors | |
void redtoyellow() | |
{ | |
digitalWrite(redPin, LOW); | |
digitalWrite(bluPin, HIGH); | |
// fade up green | |
for(byte i=1; i<100; i++) { | |
byte on = i; | |
byte off = 100-on; | |
for( byte a=0; a<100; a++ ) { | |
digitalWrite(grnPin, LOW); | |
delayMicroseconds(on); | |
digitalWrite(grnPin, HIGH); | |
delayMicroseconds(off); | |
} | |
} | |
} | |
void yellowtogreen() | |
{ | |
digitalWrite(grnPin, LOW); | |
digitalWrite(bluPin, HIGH); | |
// fade down red | |
for(byte i=1; i<100; i++) { | |
byte on = 100-i; | |
byte off = i; | |
for( byte a=0; a<100; a++ ) { | |
digitalWrite(redPin, LOW); | |
delayMicroseconds(on); | |
digitalWrite(redPin, HIGH); | |
delayMicroseconds(off); | |
} | |
} | |
} | |
void greentocyan() | |
{ | |
digitalWrite(grnPin, LOW); | |
digitalWrite(redPin, HIGH); | |
// fade up blue | |
for(byte i=1; i<100; i++) { | |
byte on = i; | |
byte off = 100-on; | |
for( byte a=0; a<100; a++ ) { | |
digitalWrite(bluPin, LOW); | |
delayMicroseconds(on); | |
digitalWrite(bluPin, HIGH); | |
delayMicroseconds(off); | |
} | |
} | |
} | |
void cyantoblue() | |
{ | |
digitalWrite(bluPin, LOW); | |
digitalWrite(redPin, HIGH); | |
// fade down green | |
for(byte i=1; i<100; i++) { | |
byte on = 100-i; | |
byte off = i; | |
for( byte a=0; a<100; a++ ) { | |
digitalWrite(grnPin, LOW); | |
delayMicroseconds(on); | |
digitalWrite(grnPin, HIGH); | |
delayMicroseconds(off); | |
} | |
} | |
} | |
void bluetomagenta() | |
{ | |
digitalWrite(bluPin, LOW); | |
digitalWrite(grnPin, HIGH); | |
// fade up red | |
for(byte i=1; i<100; i++) { | |
byte on = i; | |
byte off = 100-on; | |
for( byte a=0; a<100; a++ ) { | |
digitalWrite(redPin, LOW); | |
delayMicroseconds(on); | |
digitalWrite(redPin, HIGH); | |
delayMicroseconds(off); | |
} | |
} | |
} | |
void magentatored() | |
{ | |
digitalWrite(redPin, LOW); | |
digitalWrite(grnPin, HIGH); | |
// fade down blue | |
for(byte i=1; i<100; i++) { | |
byte on = 100-i; | |
byte off = i; | |
for( byte a=0; a<100; a++ ) { | |
digitalWrite(bluPin, LOW); | |
delayMicroseconds(on); | |
digitalWrite(bluPin, HIGH); | |
delayMicroseconds(off); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment