Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Create our rgb structure and declare it below as a global
- */
- typedef struct {
- unsigned char red;
- unsigned char green;
- unsigned char blue;
- } rgb;
- rgb channels = { 255, 0, 0 };
- /**
- * RGB Rainbow sequencing function. 100% dependent on clock speed.
- * Alternative to including math.h and using sin(), as doubles and floats
- * increase the size of the compiled avr firmware.
- */
- void rainbow_sequence(void) {
- //Fade from blue to red
- if(channels.blue > 0 && channels.red == 255 && channels.green == 0) {
- channels.blue--;
- }
- if(channels.blue == 255 && channels.red < 255 && channels.green == 0) {
- channels.red++;
- }
- //Fade from green to blue
- if(channels.green > 0 && channels.blue == 255 && channels.red == 0) {
- channels.green--;
- }
- if(channels.green == 255 && channels.blue < 255 && channels.red == 0) {
- channels.blue++;
- }
- // Fade from red to green
- if(channels.red > 0 && channels.green == 255 && channels.blue == 0) {
- channels.red--;
- }
- if(channels.red == 255 && channels.green < 255 && channels.blue == 0) {
- channels.green++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment