Skip to content

Instantly share code, notes, and snippets.

@MargenauMaker
Created February 17, 2018 09:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MargenauMaker/fbadc5eeb2608d83882d2d66a91d12c7 to your computer and use it in GitHub Desktop.
Save MargenauMaker/fbadc5eeb2608d83882d2d66a91d12c7 to your computer and use it in GitHub Desktop.
/*
Lilymini ProtoSnap Activity 2: Basic Color Mixing
SparkFun Electronics
https://www.sparkfun.com/products/14346
Modified 16 Feb 2018
by K Margenau
Create primary and secondary colors on the built-in RGB (Red/Green/Blue) LED
This code is released under the MIT License (http://opensource.org/licenses/MIT)
******************************************************************************/
// The LilyMinihas a built-in RGB (Red / Green / Blue) LED.
// In this activity we'll use digitalWrite to tun the three LEDs on and off
// in various combinations to create eight primary and secondary colors.
// Create integer variables for our LED pins:
// The built-in LED:
int RGB_red = 5;
int RGB_green = 6;
int RGB_blue = 7;
// The colored LEDs along the bottom edge of the board:
void setup()
{
// Make all of our LED pins outputs:
pinMode(RGB_red, OUTPUT);
pinMode(RGB_green, OUTPUT);
pinMode(RGB_blue, OUTPUT);
}
void loop()
{
// This code will step through the six primary and secondary colors, plus white and black.
// HIGH turns a light on with the protosnap
// For each of these colors, we'll turn the necessary RGB LEDs on or off.
// white (all LEDs on)
digitalWrite(RGB_red, HIGH);
digitalWrite(RGB_green, HIGH);
digitalWrite(RGB_blue, HIGH);
delay(1000);
// cyan (green + blue)
digitalWrite(RGB_red, LOW);
digitalWrite(RGB_green, HIGH);
digitalWrite(RGB_blue, HIGH);
delay(2000);
// blue (red and green are off)
digitalWrite(RGB_red, LOW);
digitalWrite(RGB_green, LOW);
digitalWrite(RGB_blue, HIGH);
delay(3000);
// magenta (red + blue)
digitalWrite(RGB_red, HIGH);
digitalWrite(RGB_green, LOW);
digitalWrite(RGB_blue, HIGH);
delay(4000);
// red (blue and green off)
digitalWrite(RGB_red, HIGH);
digitalWrite(RGB_green, LOW);
digitalWrite(RGB_blue, LOW);
delay(5000);
// yellow (red + green)
digitalWrite(RGB_red, HIGH);
digitalWrite(RGB_green, HIGH);
digitalWrite(RGB_blue, LOW);
delay(6000);
// green (red and blue LEDs off)
digitalWrite(RGB_red, LOW);
digitalWrite(RGB_green, HIGH);
digitalWrite(RGB_blue, LOW);
delay(7000);
// black (all LEDs off)
digitalWrite(RGB_red, LOW);
digitalWrite(RGB_green, LOW);
digitalWrite(RGB_blue, LOW);
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment