Back to Parent

/*******************************Reference:
DC motor: http://www.goodliffe.org.uk/arduino/dcmotor.php
Pixel Ring: https://github.com/technobly/SparkCore-NeoPixel/blob/master/firmware/examples/extra-examples.cpp
***************************************/

#include "application.h"
#include "neopixel.h"

/*******************setting time variables*****************/
int timeH = 0;
int timeM = 0;
int timeW = 0;

/**********************setting LED lines********************/
#define PIXEL_TYPE WS2812B
int pixelCount = 24;
int pixelPin = D0;
int pixelCount2 = 12;
int pixelPin2 = D1;

/*********************Ring 1 and Ring 2**********************/
Adafruit_NeoPixel strip = Adafruit_NeoPixel(pixelCount, pixelPin, PIXEL_TYPE);
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(pixelCount2, pixelPin2, PIXEL_TYPE);

/*******************setting LED colors for different functions*****************/
uint32_t beerColor = strip.Color(158,93,9);
int calendarColor = strip.Color(37, 167, 57);
int instagramColor = strip.Color(0, 130, 250);
int emailColor = strip.Color(255, 51, 98);
int offColor = strip.Color(0, 0, 0);

/*******************setting pump lines*****************/
int pumpPin = A1;
int delayTime = 30;

/*******************main functions*****************/
void setup()
{
  Time.zone(-5);

  //set the ring
  strip.begin();
  strip.show();

  pinMode(pumpPin, OUTPUT);
  //report time details for debug
  Spark.variable("H", &timeH, INT);
  Spark.variable("M", &timeM, INT);
  Spark.variable("W", &timeW, INT);

  Spark.function("emailC",colorForEmail);
  Spark.function("calendar",colorForCalendar);
  Spark.function("instagram",colorForInstagram);
}

void loop()
{
  //get the time any time
  timeH = Time.hour();
  timeM = Time.minute();
  timeW = Time.weekday();

   //set daily activity
  if(timeW >= 0 && timeW <= 5)
  {
     
      if(timeW == 2 && timeH == 16 && timeM >= 0)
      {
        clubLight();
      }
      else
        colorWipe(beerColor, 800);
 

      if(timeH == 8)
      {
        drivePump();  
      } 
  }
}

/*******************setting Pump (DC motor)*****************/
void drivePump()
{
  if(timeM >= 30 && timeM <= 32)
    {
         analogWrite(pumpPin, 255);
    }
    else
    {
        analogWrite(pumpPin, 0);
    }
}

/*******************setting light function*****************/
void colorWipe(int c, int wait)
{
  for(uint16_t i=0; i<strip.numPixels(); i++)
  {

    strip.setPixelColor(i, c);
    strip2.setPixelColor(i, c);
    strip.show();
    strip2.show();
    delay(wait);
  }
}

//friday night light
void clubLight()
{
  int i, j;
  
  for(j=0; j<256; j++) 
  {
    for(i=0; i<strip.numPixels(); i++) 
    {
      strip.setPixelColor(i, Wheel((i+j) & 255));
    }
    for(i=0; i<strip2.numPixels(); i++) 
    {
      strip2.setPixelColor(i, Wheel((i+j) & 255));
    }
    
    strip.show();
    strip2.show();
    delay(delayTime);
  }
}

int Wheel(byte WheelPos) 
{
  if(WheelPos < 85) 
  {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) 
  {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else 
  {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}
/*******************setting website function*****************/
//email color
int colorForEmail(String command)
{
  int i;
  int j;
  int z = 3;
  for(j = 0; j< 5; j++)
  {
  for(i=0; i<strip.numPixels(); i=i+z)
  {
    strip.setPixelColor(i, emailColor);
  }

  strip.show();

  int w = command.toInt();
  delay(w);
  z--;
  }
  colorWipe(beerColor, 800);
  return 1;
}

//calendarColor
int colorForCalendar(String command)
{
  int i;
  int j;
  for(j = 0; j< 5; j++)
  {
  for(i=0; i<strip.numPixels(); i++)
  {
    strip.setPixelColor(i, calendarColor);
  }
  strip.show();
  int w = command.toInt();
  delay(w);
  }
 
  colorWipe(beerColor, 800);
   return 1;
}

//instagram
int colorForInstagram(String command)
{
  int i;
  for(i=0; i<strip.numPixels(); i++)
  {
    strip.setPixelColor(i, instagramColor);
  }
  strip.show();
  
  for(i=0; i<strip2.numPixels(); i++)
  {
    strip2.setPixelColor(i, strip2.Color(0, 50, 200));
  }
  strip2.show();
  
  int w = command.toInt();
  
  delay(w);
  
  colorWipe(beerColor, 800);
  return 1;
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

1