Skip to content

Instantly share code, notes, and snippets.

@tonious
Forked from azend/gist:4665035
Created May 6, 2013 01:07
Show Gist options
  • Save tonious/5522809 to your computer and use it in GitHub Desktop.
Save tonious/5522809 to your computer and use it in GitHub Desktop.
Azend's colour fader modified for a smooth progression using the power of trigonometry.
/* Diyode CodeShield Pinout Constants */
#define ENCODER_A 14
#define ENCODER_B 15
#define ENCODER_PORT PINC
#define SWITCH 13
#define BUTTON 12
#define RGB_RED 11
#define RGB_GREEN 10
#define RGB_BLUE 9
#define LED 6
#define SERVO 5
#define PIEZO 3
#define RELAY 2
#define POT 2
#define HALL 3
#define THERMISTOR 4
#define PHOTOCELL 5
double angle = 0;
void setup () {
pinMode( RGB_RED, OUTPUT );
pinMode( RGB_GREEN, OUTPUT );
pinMode( RGB_BLUE, OUTPUT );
}
void loop () {
analogWrite( RGB_RED, byte( sin(angle) * 127 + 128));
analogWrite( RGB_GREEN, byte( sin(angle + PI * 2/3) * 127 + 128 ) );
analogWrite( RGB_BLUE, byte( sin(angle - PI * 2/3) * 127 + 128 ) );
delay (15);
angle+= 0.01;
if( angle > PI * 2 ) angle = 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment