#include <Adafruit_NeoPixel.h> // Library for NeoPixels
#define pinPix1 1 // Single neopixel 1
#define pinPix2 2 // Single neopixel 2
#define pinPix3 3 // Single neopixel 3
#define pinPix4 4 // Single neopixel 4
#define pinPix5 5 // Single neopixel 5
#define pinPix6 6 // Single neopixel 6
#define pinPix7 7 // Neopixel 12s
#define numPix 12 // Number of NeoPixels in the Ring
#define numPix2 1 // Number of NeoPixels in singles
//Selecting pins for the Photoresistors (DIGITAL ONLY) [INSERT NUMBERS]
int Photores1 = 8;
int Photores2 = 9;
int Photores3 = 10;
int Photores4 = 11;
int Photores5 = 12;
int Photores6 = 13;
//Variables to determine stage and what lights turn on
int stage = 1;
int randomLED1 = 0;
int randomLED2 = 0;
// Setup NeoPixel Ring
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number driving the strip
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel myNeoPixelsRing = Adafruit_NeoPixel(numPix, pinPix7, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel myNeoPixels1 = Adafruit_NeoPixel(numPix2, pinPix1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel myNeoPixels2 = Adafruit_NeoPixel(numPix2, pinPix2, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel myNeoPixels3 = Adafruit_NeoPixel(numPix2, pinPix3, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel myNeoPixels4 = Adafruit_NeoPixel(numPix2, pinPix4, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel myNeoPixels5 = Adafruit_NeoPixel(numPix2, pinPix5, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel myNeoPixels6 = Adafruit_NeoPixel(numPix2, pinPix6, NEO_GRB + NEO_KHZ800);
//------------------------SETUP START-------------------------------------------------------
void setup() {
myNeoPixelsRing.begin(); // Initialize the NeoPixel array in the Arduino's memory,
myNeoPixels1.begin();
myNeoPixels2.begin();
myNeoPixels3.begin();
myNeoPixels4.begin();
myNeoPixels5.begin();
myNeoPixels6.begin();
myNeoPixelsRing.show(); // turn all pixels off, and upload to ring or string
myNeoPixels1.show();
myNeoPixels2.show();
myNeoPixels3.show();
myNeoPixels4.show();
myNeoPixels5.show();
myNeoPixels6.show();
//Keep Analogpin 0 unwired for random numbers
randomSeed(analogRead(0));
getRandomNumbers();
//Setting up input pins
pinMode(Photores1, INPUT);
pinMode(Photores2, INPUT);
pinMode(Photores3, INPUT);
pinMode(Photores4, INPUT);
pinMode(Photores5, INPUT);
pinMode(Photores6, INPUT);
}
//--------------------------SETUP END-------------------------------------------------------
//--------------------------LOOP START-----------------------------------------------------
//Photoresistor value 0 = light, 1 = dark
void loop() {
//Serial.println(randomLED1);
//Serial.println(randomLED2);
//Stage 1: The First LED/Hand on the ball
if (stage == 1)
{
if (randomLED1 == 1) //checking which LED was selected
{
myNeoPixels1.setPixelColor(0, 140, 85, 180);
myNeoPixels1.show();
if (digitalRead(Photores1) == 1) //checking whether sensor is dark (0 = light, 1 = dark)
{
stage = 2; //if dark move onto the second LED
turnoffLEDs(); //Function to turn off all LEDs
}
}
else if (randomLED1 == 2) //checking which LED was selected
{
myNeoPixels2.setPixelColor(0, 140, 85, 180);
myNeoPixels2.show();
if (digitalRead(Photores2) == 1) //checking whether sensor is dark (0 = light, 1 = dark)
{
stage = 2; //if dark move onto the second LED
turnoffLEDs(); //Function to turn off all LEDs
}
}
else if (randomLED1 == 3) //checking which LED was selected
{
myNeoPixels3.setPixelColor(0, 140, 85, 180);
myNeoPixels3.show();
if (digitalRead(Photores3) == 1) //checking whether sensor is dark (0 = light, 1 = dark)
{
stage = 2; //if dark move onto the second LED
turnoffLEDs(); //Function to turn off all LEDs
}
}
else if (randomLED1 == 4) //checking which LED was selected
{
myNeoPixels4.setPixelColor(0, 140, 85, 180);
myNeoPixels4.show();
if (digitalRead(Photores4) == 1) //checking whether sensor is dark (0 = light, 1 = dark)
{
stage = 2; //if dark move onto the second LED
turnoffLEDs(); //Function to turn off all LEDs
}
}
else if (randomLED1 == 5) //checking which LED was selected
{
myNeoPixels5.setPixelColor(0, 140, 85, 180);
myNeoPixels5.show();
if (digitalRead(Photores5) == 1) //checking whether sensor is dark (0 = light, 1 = dark)
{
stage = 2; //if dark move onto the second LED
turnoffLEDs(); //Function to turn off all LEDs
}
}
else if (randomLED1 == 6) //checking which LED was selected
{
myNeoPixels6.setPixelColor(0, 140, 85, 180);
myNeoPixels6.show();
if (digitalRead(Photores6) == 1) //checking whether sensor is dark (0 = light, 1 = dark)
{
stage = 2; //if dark move onto the second LED
turnoffLEDs(); //Function to turn off all LEDs
}
}
}
//Stage 2: the Second LED/Hand on the ball
if (stage == 2)
{
if (randomLED2 == 1) //checking which LED was selected
{
myNeoPixels1.setPixelColor(0, 0, 0, 255);
myNeoPixels1.show();
if (digitalRead(Photores1) == 1) //checking whether sensor is dark (0 = light, 1 = dark)
{
stage = 3; //if dark move onto the second LED
turnoffLEDs(); //Function to turn off all LEDs
}
}
else if (randomLED2 == 2) //checking which LED was selected
{
myNeoPixels2.setPixelColor(0, 0, 0, 255);
myNeoPixels2.show();
if (digitalRead(Photores2) == 1) //checking whether sensor is dark (0 = light, 1 = dark)
{
stage = 3; //if dark move onto the second LED
turnoffLEDs(); //Function to turn off all LEDs
}
}
else if (randomLED2 == 3) //checking which LED was selected
{
myNeoPixels3.setPixelColor(0, 0, 0, 255);
myNeoPixels3.show();
if (digitalRead(Photores3) == 1) //checking whether sensor is dark (0 = light, 1 = dark)
{
stage = 3; //if dark move onto the second LED
turnoffLEDs(); //Function to turn off all LEDs
}
}
else if (randomLED2 == 4) //checking which LED was selected
{
myNeoPixels4.setPixelColor(0, 0, 0, 255);
myNeoPixels4.show();
if (digitalRead(Photores4) == 1) //checking whether sensor is dark (0 = light, 1 = dark)
{
stage = 3; //if dark move onto the second LED
turnoffLEDs(); //Function to turn off all LEDs
}
}
else if (randomLED2 == 5) //checking which LED was selected
{
myNeoPixels5.setPixelColor(0, 0, 0, 255);
myNeoPixels5.show();
if (digitalRead(Photores5) == 1) //checking whether sensor is dark (0 = light, 1 = dark)
{
stage = 3; //if dark move onto the second LED
turnoffLEDs(); //Function to turn off all LEDs
}
}
else if (randomLED2 == 6) //checking which LED was selected
{
myNeoPixels6.setPixelColor(0, 0, 0, 255);
myNeoPixels6.show();
if (digitalRead(Photores6) == 1) //checking whether sensor is dark (0 = light, 1 = dark)
{
stage = 3; //if dark move onto the second LED
turnoffLEDs(); //Function to turn off all LEDs
}
}
}
//Stage 3: Breathing and reseting stage counters
else if (stage == 3)
{
allbreathe(20, 100, 255, 0, 0); // Pause; Number of steps; Full-on R,G,B values RED
allbreathe(20, 100, 255, 160, 0); // Orange
allbreathe(20, 100, 255, 255, 0); // Yellow
allbreathe(20, 100, 0, 255, 0); // Green
allbreathe(20, 100, 0, 0, 255); // Blue
allbreathe(20, 100, 0, 255, 255); // Cyan
allbreathe(20, 100, 255, 0, 255); // Magenta
allbreathe(20, 100, 140, 85, 180); // Purple
stage = 1;
getRandomNumbers();
}
delay(500);
//breathe(20, 100, 255, 0, 0); // Pause; Number of steps; Full-on R,G,B values RED
//breathe(20, 100, 255, 160, 0); // Orange
//breathe(20, 100, 255, 255, 0); // Yellow
//breathe(20, 100, 0, 255, 0); // Green
//breathe(20, 100, 0, 0, 255); // Blue
//breathe(20, 100, 0, 255, 255); // Cyan
//breathe(20, 100, 255, 0, 255); // Magenta
//breathe(20, 100, 140, 85, 180); // Purple
//if (analogRead(A0) > 20) Serial.println("Light");
//else Serial.println("Dark");
//delay(1000);
}
//----------------------LOOP END-----------------------------------------------------
//---------------------ALL LEDS BREATHE START------------------------------------------
// Pause = delay between transitions
// Steps = number of steps
// R, G, B = Full-on RGB values
void allbreathe(int pause, int steps, byte R, byte G, byte B) {
int tmpR, tmpG, tmpB; // Temp values
// Fade up
for (int s = 1; s <= steps; s++) {
tmpR = (R * s) / steps; // Multiply first to avoid truncation errors
tmpG = (G * s) / steps;
tmpB = (B * s) / steps;
for (int i = 0; i < numPix; i++) {
myNeoPixelsRing.setPixelColor(i, tmpR, tmpG, tmpB);
myNeoPixels1.setPixelColor(i, tmpR, tmpG, tmpB);
myNeoPixels2.setPixelColor(i, tmpR, tmpG, tmpB);
myNeoPixels3.setPixelColor(i, tmpR, tmpG, tmpB);
myNeoPixels4.setPixelColor(i, tmpR, tmpG, tmpB);
myNeoPixels5.setPixelColor(i, tmpR, tmpG, tmpB);
myNeoPixels6.setPixelColor(i, tmpR, tmpG, tmpB);
}
myNeoPixelsRing.show();
myNeoPixels1.show();
myNeoPixels2.show();
myNeoPixels3.show();
myNeoPixels4.show();
myNeoPixels5.show();
myNeoPixels6.show();
delay(pause);
}
// Fade down
for (int s = steps; s > 0; s--) {
tmpR = (R * s) / steps; // Multiply first to avoid truncation errors
tmpG = (G * s) / steps;
tmpB = (B * s) / steps;
for (int i = 0; i < numPix; i++) {
myNeoPixelsRing.setPixelColor(i, tmpR, tmpG, tmpB);
myNeoPixels1.setPixelColor(i, tmpR, tmpG, tmpB);
myNeoPixels2.setPixelColor(i, tmpR, tmpG, tmpB);
myNeoPixels3.setPixelColor(i, tmpR, tmpG, tmpB);
myNeoPixels4.setPixelColor(i, tmpR, tmpG, tmpB);
myNeoPixels5.setPixelColor(i, tmpR, tmpG, tmpB);
myNeoPixels6.setPixelColor(i, tmpR, tmpG, tmpB);
}
myNeoPixelsRing.show();
myNeoPixels1.show();
myNeoPixels2.show();
myNeoPixels3.show();
myNeoPixels4.show();
myNeoPixels5.show();
myNeoPixels6.show();
delay(pause);
}
delay(pause * 5); /*Pause before the beginning of new loop */
}
//---------------ALL LEDS BREATHE END-----------------------------------------------------
//---------------------ALL INDIVIDUAL LEDS BREATHE START------------------------------------
// Pause = delay between transitions
// Steps = number of steps
// R, G, B = Full-on RGB values
void indbreathe(int pause, int steps, byte R, byte G, byte B) {
int tmpR, tmpG, tmpB; // Temp values
// Fade up
for (int s = 1; s <= steps; s++) {
tmpR = (R * s) / steps; // Multiply first to avoid truncation errors
tmpG = (G * s) / steps;
tmpB = (B * s) / steps;
for (int i = 0; i < numPix; i++) {
myNeoPixels1.setPixelColor(i, tmpR, tmpG, tmpB);
myNeoPixels2.setPixelColor(i, tmpR, tmpG, tmpB);
myNeoPixels3.setPixelColor(i, tmpR, tmpG, tmpB);
myNeoPixels4.setPixelColor(i, tmpR, tmpG, tmpB);
myNeoPixels5.setPixelColor(i, tmpR, tmpG, tmpB);
myNeoPixels6.setPixelColor(i, tmpR, tmpG, tmpB);
}
myNeoPixels1.show();
myNeoPixels2.show();
myNeoPixels3.show();
myNeoPixels4.show();
myNeoPixels5.show();
myNeoPixels6.show();
delay(pause);
}
// Fade down
for (int s = steps; s > 0; s--) {
tmpR = (R * s) / steps; // Multiply first to avoid truncation errors
tmpG = (G * s) / steps;
tmpB = (B * s) / steps;
for (int i = 0; i < numPix; i++) {
myNeoPixels1.setPixelColor(i, tmpR, tmpG, tmpB);
myNeoPixels2.setPixelColor(i, tmpR, tmpG, tmpB);
myNeoPixels3.setPixelColor(i, tmpR, tmpG, tmpB);
myNeoPixels4.setPixelColor(i, tmpR, tmpG, tmpB);
myNeoPixels5.setPixelColor(i, tmpR, tmpG, tmpB);
myNeoPixels6.setPixelColor(i, tmpR, tmpG, tmpB);
}
myNeoPixels1.show();
myNeoPixels2.show();
myNeoPixels3.show();
myNeoPixels4.show();
myNeoPixels5.show();
myNeoPixels6.show();
delay(pause);
}
delay(pause * 5); /*Pause before the beginning of new loop */
}
//---------------ALL INDIVIDUAL LEDS BREATHE END------------------------------------------
//-----------------------LED 1 START---------------------------------------------------------
// Pause = delay between transitions
// Steps = number of steps
// R, G, B = Full-on RGB values
void breathe1(int pause, int steps, byte R, byte G, byte B) {
int tmpR, tmpG, tmpB; // Temp values
// Fade up
for (int s = 1; s <= steps; s++) {
tmpR = (R * s) / steps; // Multiply first to avoid truncation errors
tmpG = (G * s) / steps;
tmpB = (B * s) / steps;
for (int i = 0; i < numPix; i++) {
myNeoPixels1.setPixelColor(i, tmpR, tmpG, tmpB);
}
myNeoPixels1.show();
delay(pause);
}
// Fade down
for (int s = steps; s > 0; s--) {
tmpR = (R * s) / steps; // Multiply first to avoid truncation errors
tmpG = (G * s) / steps;
tmpB = (B * s) / steps;
for (int i = 0; i < numPix; i++) {
myNeoPixels1.setPixelColor(i, tmpR, tmpG, tmpB);
}
myNeoPixels1.show();
delay(pause);
}
delay(pause * 5); /*Pause before the beginning of new loop */
}
//----------------------LED 1 END----------------------------------------------------------
//----------------------LED 2 START--------------------------------------------------------
void breathe2(int pause, int steps, byte R, byte G, byte B) {
int tmpR, tmpG, tmpB; // Temp values
// Fade up
for (int s = 1; s <= steps; s++) {
tmpR = (R * s) / steps; // Multiply first to avoid truncation errors
tmpG = (G * s) / steps;
tmpB = (B * s) / steps;
for (int i = 0; i < numPix; i++) {
myNeoPixels2.setPixelColor(i, tmpR, tmpG, tmpB);
}
myNeoPixels2.show();
delay(pause);
}
// Fade down
for (int s = steps; s > 0; s--) {
tmpR = (R * s) / steps; // Multiply first to avoid truncation errors
tmpG = (G * s) / steps;
tmpB = (B * s) / steps;
for (int i = 0; i < numPix; i++) {
myNeoPixels2.setPixelColor(i, tmpR, tmpG, tmpB);
}
myNeoPixels2.show();
delay(pause);
}
delay(pause * 5); /*Pause before the beginning of new loop */
}
//---------------------------LED 2 END-------------------------------------------------
//--------------------------LED 3 START------------------------------------------------
void breathe3(int pause, int steps, byte R, byte G, byte B) {
int tmpR, tmpG, tmpB; // Temp values
// Fade up
for (int s = 1; s <= steps; s++) {
tmpR = (R * s) / steps; // Multiply first to avoid truncation errors
tmpG = (G * s) / steps;
tmpB = (B * s) / steps;
for (int i = 0; i < numPix; i++) {
myNeoPixels3.setPixelColor(i, tmpR, tmpG, tmpB);
}
myNeoPixels3.show();
delay(pause);
}
// Fade down
for (int s = steps; s > 0; s--) {
tmpR = (R * s) / steps; // Multiply first to avoid truncation errors
tmpG = (G * s) / steps;
tmpB = (B * s) / steps;
for (int i = 0; i < numPix; i++) {
myNeoPixels3.setPixelColor(i, tmpR, tmpG, tmpB);
}
myNeoPixels3.show();
delay(pause);
}
delay(pause * 5); /*Pause before the beginning of new loop */
}
//-----------------------------LED 3 END-----------------------------------------------
//----------------------------LED 4 START---------------------------------------------
void breathe4(int pause, int steps, byte R, byte G, byte B) {
int tmpR, tmpG, tmpB; // Temp values
// Fade up
for (int s = 1; s <= steps; s++) {
tmpR = (R * s) / steps; // Multiply first to avoid truncation errors
tmpG = (G * s) / steps;
tmpB = (B * s) / steps;
for (int i = 0; i < numPix; i++) {
myNeoPixels4.setPixelColor(i, tmpR, tmpG, tmpB);
}
myNeoPixels4.show();
delay(pause);
}
// Fade down
for (int s = steps; s > 0; s--) {
tmpR = (R * s) / steps; // Multiply first to avoid truncation errors
tmpG = (G * s) / steps;
tmpB = (B * s) / steps;
for (int i = 0; i < numPix; i++) {
myNeoPixels4.setPixelColor(i, tmpR, tmpG, tmpB);
}
myNeoPixels4.show();
delay(pause);
}
delay(pause * 5); /*Pause before the beginning of new loop */
}
//--------------------------LED 4 END---------------------------------------------------
//--------------------------LED 5 START-------------------------------------------------
void breathe5(int pause, int steps, byte R, byte G, byte B) {
int tmpR, tmpG, tmpB; // Temp values
// Fade up
for (int s = 1; s <= steps; s++) {
tmpR = (R * s) / steps; // Multiply first to avoid truncation errors
tmpG = (G * s) / steps;
tmpB = (B * s) / steps;
for (int i = 0; i < numPix; i++) {
myNeoPixels5.setPixelColor(i, tmpR, tmpG, tmpB);
}
myNeoPixels5.show();
delay(pause);
}
// Fade down
for (int s = steps; s > 0; s--) {
tmpR = (R * s) / steps; // Multiply first to avoid truncation errors
tmpG = (G * s) / steps;
tmpB = (B * s) / steps;
for (int i = 0; i < numPix; i++) {
myNeoPixels5.setPixelColor(i, tmpR, tmpG, tmpB);
}
myNeoPixels5.show();
delay(pause);
}
delay(pause * 5); /*Pause before the beginning of new loop */
}
//----------------------------LED 5 END--------------------------------------------------
//---------------------------LED 6 START------------------------------------------------
void breathe6(int pause, int steps, byte R, byte G, byte B) {
int tmpR, tmpG, tmpB; // Temp values
// Fade up
for (int s = 1; s <= steps; s++) {
tmpR = (R * s) / steps; // Multiply first to avoid truncation errors
tmpG = (G * s) / steps;
tmpB = (B * s) / steps;
for (int i = 0; i < numPix; i++) {
myNeoPixels6.setPixelColor(i, tmpR, tmpG, tmpB);
}
myNeoPixels6.show();
delay(pause);
}
// Fade down
for (int s = steps; s > 0; s--) {
tmpR = (R * s) / steps; // Multiply first to avoid truncation errors
tmpG = (G * s) / steps;
tmpB = (B * s) / steps;
for (int i = 0; i < numPix; i++) {
myNeoPixels6.setPixelColor(i, tmpR, tmpG, tmpB);
}
myNeoPixels6.show();
delay(pause);
}
delay(pause * 5); /*Pause before the beginning of new loop */
}
//------------------------LED 6 END--------------------------------------------------
//--------------RING BREATHE START------------------------------------------------------
// Pause = delay between transitions
// Steps = number of steps
// R, G, B = Full-on RGB values
void ringbreathe(int pause, int steps, byte R, byte G, byte B) {
int tmpR, tmpG, tmpB; // Temp values
// Fade up
for (int s = 1; s <= steps; s++) {
tmpR = (R * s) / steps; // Multiply first to avoid truncation errors
tmpG = (G * s) / steps;
tmpB = (B * s) / steps;
for (int i = 0; i < numPix; i++) {
myNeoPixelsRing.setPixelColor(i, tmpR, tmpG, tmpB);
}
myNeoPixelsRing.show();
delay(pause);
}
// Fade down
for (int s = steps; s > 0; s--) {
tmpR = (R * s) / steps; // Multiply first to avoid truncation errors
tmpG = (G * s) / steps;
tmpB = (B * s) / steps;
for (int i = 0; i < numPix; i++) {
myNeoPixelsRing.setPixelColor(i, tmpR, tmpG, tmpB);
}
myNeoPixelsRing.show();
delay(pause);
}
delay(pause * 5); /*Pause before the beginning of new loop */
}
//----------------TURN OFF ALL LEDS START-------------------------------------------------
//function to turn off all the neopixel LEDs NEED TO WRITE****************
void turnoffLEDs()
{
myNeoPixelsRing.clear();
myNeoPixels1.clear();
myNeoPixels2.clear();
myNeoPixels3.clear();
myNeoPixels4.clear();
myNeoPixels5.clear();
myNeoPixels6.clear();
}
//-------------------TURN OFF ALL LEDS END--------------------------------------------------
void getRandomNumbers()
{
randomLED1 = random(1, 6);
randomLED2 = random(1, 6);
if (randomLED1 == randomLED2) //If they are equal to each other (1/6 chance), set them to predetermined values
{
randomLED1 = 3;
randomLED2 = 6;
}
}