Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- //Nick, 2016
- #include <NeoPixelBus.h>
- #include <NeoPixelAnimator.h>
- #include <NeoPixelBrightnessBus.h>
- //#include <Adafruit_GFX.h>
- //#include <Adafruit_NeoMatrix.h>
- //#include <Adafruit_NeoPixel.h>
- #include <Wire.h> //http://arduino.cc/en/Reference/Wire (included with Arduino IDE)
- #include "RTClib.h"
- #include <BH1750.h>
- /*
- BH1750 can be physically configured to use two I2C addresses:
- - 0x23 (most common) (if ADD pin had < 0.7VCC voltage)
- - 0x5C (if ADD pin had > 0.7VCC voltage)
- Library use 0x23 address as default, but you can define any other address.
- If you had troubles with default value - try to change it to 0x5C.
- */
- BH1750 lightMeter(0x23);
- //IF CLOCK TIME IS WRONG: RUN FILE->EXAMPLE->DS1307RTC->SET TIME
- RTC_DS3231 rtc;
- //LED pin = GPIO 3 for ESP8266, = pin 3 for Oak
- typedef ColumnMajorAlternating270Layout MyPanelLayout;
- const uint8_t PanelWidth = 16;
- const uint8_t PanelHeight = 6;
- const uint16_t PixelCount = PanelWidth * PanelHeight;
- NeoTopology<MyPanelLayout> topo(PanelWidth, PanelHeight);
- NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount);
- RgbColor red(128, 0, 0);
- RgbColor green(0, 128, 0);
- RgbColor blue(0, 0, 128);
- RgbColor white(128);
- RgbColor black(0);
- const uint16_t left = 0;
- const uint16_t right = PanelWidth - 1;
- const uint16_t top = 0;
- const uint16_t bottom = PanelHeight - 1;
- const uint8_t AnimationChannels = 5;
- NeoPixelAnimator animations(AnimationChannels); // NeoPixel animation management object
- uint16_t effectState = 0; // general purpose variable used to store effect state
- // what is stored for state is specific to the need, in this case, the colors.
- // basically what ever you need inside the animation update function
- struct MyAnimationState
- {
- RgbColor StartingColor;
- RgbColor EndingColor;
- };
- // one entry per pixel to match the animation timing manager
- MyAnimationState animationState[AnimationChannels];
- //constants
- const int wpause = 250;
- //variables
- long lastMillis = 0;
- long serialMillis = 0;
- int fadeInterval = 25;
- int intBrightness = 200;
- int mytimemonth;
- int mytimeday;
- int mytimehr;
- int mytimemin;
- int mytimesec;
- //states (variables)
- int sNEAR = LOW;
- int sPAST = LOW;
- int sEXACTLY = LOW;
- int sA1 = LOW;
- int sQUARTER = LOW;
- int sTWENTY = LOW;
- int sMTEN = LOW;
- int sA2 = LOW;
- int sMFIVE = LOW;
- int sA3 = LOW;
- int sHALF = LOW;
- int sTO = LOW;
- int sPAST2 = LOW;
- int sTEN = LOW;
- int sFOUR = LOW;
- int sTHREE = LOW;
- int sE1 = LOW;
- int sEIGHT = LOW;
- int sSEVEN = LOW;
- int sN1 = LOW;
- int sNINE = LOW;
- int sE2 = LOW;
- int sELEVEN = LOW;
- int sTWO = LOW;
- int sFIVE = LOW;
- int sONE = LOW;
- int sSIX = LOW;
- int sTWELVE = LOW;
- void setup() {
- Serial.begin(57600); //Begin serial communcation (for photoresistor to display on serial monitor)
- // This info pulled from RTClib.h
- if (! rtc.begin()) {
- //Serial.println("Couldn't find RTC"); //program LEDs to show "NO CLOCK"
- while (1);
- }
- if (rtc.lostPower()) {
- Serial.println("RTC lost power, lets set the time!"); //program LEDs to show "SET CLOCK"
- //following line sets the RTC to the date & time this sketch was compiled
- rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
- // This line sets the RTC with an explicit date & time, for example to set
- // January 21, 2014 at 3am you would call:
- // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
- }
- Serial.println("Power on");
- Particle.publish("Power On", PRIVATE);
- lightMeter.begin(BH1750_CONTINUOUS_HIGH_RES_MODE);
- Serial.println(F("BH1750 Test"));
- strip.Begin();
- strip.Show();
- }
- void near (int state){
- //this word's details
- int iRow = 0;
- int arrCols[] = {0,1,2,3};
- int arrSize = (sizeof(arrCols)/sizeof(arrCols[0])); //find array size so we don't read random values
- int& wstate = sNEAR; //int&
- displayWord(iRow, arrCols, arrSize, wstate, state); // not working with state
- }
- void past (int state){
- int iRow = 0;
- int arrCols[] = {4,5,6,7};
- int arrSize = (sizeof(arrCols)/sizeof(arrCols[0])); //find array size so we don't read random values
- int& wstate = sPAST; //int&
- displayWord(iRow, arrCols, arrSize, wstate, state); // not working with state
- }
- void exactly (int state){
- int iRow = 0;
- int arrCols[] = {8,9,10,11,12,13,14};
- int arrSize = (sizeof(arrCols)/sizeof(arrCols[0])); //find array size so we don't read random values
- int& wstate = sEXACTLY;
- displayWord(iRow, arrCols, arrSize, wstate, state); // not working with state
- }
- void a1 (int state){
- int iRow = 0;
- int arrCols[] = {15};
- int arrSize = (sizeof(arrCols)/sizeof(arrCols[0])); //find array size so we don't read random values
- int& wstate = sA1; //int&
- displayWord(iRow, arrCols, arrSize, wstate, state); // not working with state
- }
- void quarter (int state){
- int iRow = 1;
- int arrCols[] = {0,1,2,3,4,5,6};
- int arrSize = (sizeof(arrCols)/sizeof(arrCols[0])); //find array size so we don't read random values
- int& wstate = sQUARTER; //int&
- displayWord(iRow, arrCols, arrSize, wstate, state); // not working with state
- }
- void twenty (int state){
- int iRow = 1;
- int arrCols[] = {7,8,9,10,11,12};
- int arrSize = (sizeof(arrCols)/sizeof(arrCols[0])); //find array size so we don't read random values
- int& wstate = sTWENTY; //int&
- int wait = 1000;
- displayWord(iRow, arrCols, arrSize, wstate, state); // not working with state
- }
- void mten (int state){
- int iRow = 1;
- int arrCols[] = {13,14,15};
- int arrSize = (sizeof(arrCols)/sizeof(arrCols[0])); //find array size so we don't read random values
- int& wstate = sMTEN; //int&
- displayWord(iRow, arrCols, arrSize, wstate, state); // not working with state
- }
- void a2 (int state){
- int iRow = 2;
- int arrCols[] = {0};
- int arrSize = (sizeof(arrCols)/sizeof(arrCols[0])); //find array size so we don't read random values
- int& wstate = sA2; //int&
- displayWord(iRow, arrCols, arrSize, wstate, state); // not working with state
- }
- void mfive (int state){
- int iRow = 2;
- int arrCols[] = {1,2,3,4};
- int arrSize = (sizeof(arrCols)/sizeof(arrCols[0])); //find array size so we don't read random values
- int& wstate = sMFIVE; //int&
- displayWord(iRow, arrCols, arrSize, wstate, state); // not working with state
- }
- void a3 (int state){
- int iRow = 2;
- int arrCols[] = {5};
- int arrSize = (sizeof(arrCols)/sizeof(arrCols[0])); //find array size so we don't read random values
- int& wstate = sA3; //int&
- displayWord(iRow, arrCols, arrSize, wstate, state); // not working with state
- }
- void half (int state){
- int iRow = 2;
- int arrCols[] = {6,7,8,9};
- int arrSize = (sizeof(arrCols)/sizeof(arrCols[0])); //find array size so we don't read random values
- int& wstate = sHALF; //int&
- displayWord(iRow, arrCols, arrSize, wstate, state); // not working with state
- }
- void to (int state){
- int iRow = 2;
- int arrCols[] = {10,11};
- int arrSize = (sizeof(arrCols)/sizeof(arrCols[0])); //find array size so we don't read random values
- int& wstate = sTO; //int&
- displayWord(iRow, arrCols, arrSize, wstate, state); // not working with state
- }
- void past2 (int state){
- int iRow = 2;
- int arrCols[] = {12,13,14,15};
- int arrSize = (sizeof(arrCols)/sizeof(arrCols[0])); //find array size so we don't read random values
- int& wstate = sPAST2; //int&
- displayWord(iRow, arrCols, arrSize, wstate, state); // not working with state
- }
- void ten (int state){
- int iRow = 3;
- int arrCols[] = {0,1,2};
- int arrSize = (sizeof(arrCols)/sizeof(arrCols[0])); //find array size so we don't read random values
- int& wstate = sTEN; //int&
- displayWord(iRow, arrCols, arrSize, wstate, state); // not working with state
- }
- void four (int state){
- int iRow = 3;
- int arrCols[] = {3,4,5,6};
- int arrSize = (sizeof(arrCols)/sizeof(arrCols[0])); //find array size so we don't read random values
- int& wstate = sFOUR; //int&
- displayWord(iRow, arrCols, arrSize, wstate, state); // not working with state
- }
- void three (int state){
- int iRow = 3;
- int arrCols[] = {7,8,9,10,11};
- int arrSize = (sizeof(arrCols)/sizeof(arrCols[0])); //find array size so we don't read random values
- int& wstate = sTHREE; //int&
- displayWord(iRow, arrCols, arrSize, wstate, state); // not working with state
- }
- void eight (int state){
- int iRow = 3;
- int arrCols[] = {11,12,13,14,15};
- int arrSize = (sizeof(arrCols)/sizeof(arrCols[0])); //find array size so we don't read random values
- int& wstate = sEIGHT; //int&
- displayWord(iRow, arrCols, arrSize, wstate, state); // not working with state
- }
- void seven (int state){
- int iRow = 4;
- int arrCols[] = {0,1,2,3,4};
- int arrSize = (sizeof(arrCols)/sizeof(arrCols[0])); //find array size so we don't read random values
- int& wstate = sSEVEN; //int&
- displayWord(iRow, arrCols, arrSize, wstate, state); // not working with state
- }
- void nine (int state){
- int iRow = 4;
- int arrCols[] = {4,5,6,7};
- int arrSize = (sizeof(arrCols)/sizeof(arrCols[0])); //find array size so we don't read random values
- int& wstate = sNINE; //int&
- displayWord(iRow, arrCols, arrSize, wstate, state); // not working with state
- }
- void eleven (int state){
- int iRow = 4;
- int arrCols[] = {7,8,9,10,11,12};
- int arrSize = (sizeof(arrCols)/sizeof(arrCols[0])); //find array size so we don't read random values
- int& wstate = sELEVEN; //int&
- displayWord(iRow, arrCols, arrSize, wstate, state); // not working with state
- }
- void two (int state){
- int iRow = 4;
- int arrCols[] = {13,14,15};
- int arrSize = (sizeof(arrCols)/sizeof(arrCols[0])); //find array size so we don't read random values
- int& wstate = sTWO; //int&
- displayWord(iRow, arrCols, arrSize, wstate, state); // not working with state
- }
- void five (int state){
- int iRow = 5;
- int arrCols[] = {0,1,2,3};
- int arrSize = (sizeof(arrCols)/sizeof(arrCols[0])); //find array size so we don't read random values
- int& wstate = sFIVE; //int&
- displayWord(iRow, arrCols, arrSize, wstate, state); // not working with state
- }
- void one (int state){
- int iRow = 5;
- int arrCols[] = {4,5,6};
- int arrSize = (sizeof(arrCols)/sizeof(arrCols[0])); //find array size so we don't read random values
- int& wstate = sONE; //int&
- displayWord(iRow, arrCols, arrSize, wstate, state); // not working with state
- }
- void six (int state){
- int iRow = 5;
- int arrCols[] = {7,8,9};
- int arrSize = (sizeof(arrCols)/sizeof(arrCols[0])); //find array size so we don't read random values
- int& wstate = sSIX; //int&
- displayWord(iRow, arrCols, arrSize, wstate, state); // not working with state
- }
- void twelve (int state){
- int iRow = 5;
- int arrCols[] = {10,11,12,13,14,15};
- int arrSize = (sizeof(arrCols)/sizeof(arrCols[0])); //find array size so we don't read random values
- int& wstate = sTWELVE; //int&
- displayWord(iRow, arrCols, arrSize, wstate, state); // not working with state
- }
- // Display functions
- void displayWord(int iRow, int arrCols[], int arrSize, int& shownState, int state) { //function to display word, effect if just turned on, no effect (stay on) otherwise
- if (state == ON) {
- // if (shownState == LOW) {
- // FadeIn(0.2f, arrCols, arrSize, iRow);
- // showWord(arrCols, arrSize, iRow, white);
- //void spellWord(int arrCols[], int arrSize, int iRow, RGB color, int wait){
- //spellWord(arrCols, arrSize, iRow, 2500);
- // shownState = HIGH; //we have now shown the word
- // } else {
- showWord(arrCols, arrSize, iRow, white);
- // }
- } else {
- //void hideWord(int arrCols[], int arrSize, int iRow)
- hideWord(arrCols, arrSize, iRow);
- shownState = LOW;
- }
- }
- void hideWord(int arrCols[], int arrSize, int iRow) {
- for (int i = 0; i < arrSize; i++) {
- strip.SetPixelColor(topo.Map(arrCols[i], iRow), black);
- }
- }
- void showWord(int arrCols[], int arrSize, int iRow, RgbColor colour) { //simple show word, no effect
- for (int i = 0; i < arrSize; i++) {
- strip.SetPixelColor(topo.Map(arrCols[i], iRow), colour);
- }
- }
- // simple blend function
- void BlendAnimUpdate(const AnimationParam& param)
- {
- // this gets called for each animation on every time step
- // progress will start at 0.0 and end at 1.0
- // we use the blend function on the RgbColor to mix
- // color based on the progress given to us in the animation
- RgbColor updatedColor = RgbColor::LinearBlend(
- animationState[param.index].StartingColor,
- animationState[param.index].EndingColor,
- param.progress);
- // apply the color to the strip
- strip.SetPixelColor(param.index, updatedColor);
- }
- void FadeIn(float luminance, int arrCols[], int arrSize, int iRow) {
- // Fade upto a random color
- // we use HslColor object as it allows us to easily pick a hue
- // with the same saturation and luminance so the colors picked
- // will have similiar overall brightness
- RgbColor target = HslColor(random(360) / 360.0f, 1.0f, luminance);
- uint16_t time = random(800, 2000);
- for (int i = 0; i < arrSize; i++) {
- uint16_t pixel = topo.Map(arrCols[i], iRow);
- animationState[0].StartingColor = strip.GetPixelColor(0);
- animationState[0].EndingColor = target;
- animations.StartAnimation(pixel, time, BlendAnimUpdate);
- }
- }
- // Clock
- void displayClock() {
- if ((mytimemin== 0)
- | (mytimemin== 5)
- | (mytimemin== 10)
- | (mytimemin== 15)
- | (mytimemin== 20)
- | (mytimemin== 25)
- | (mytimemin == 30)
- | (mytimemin == 35)
- | (mytimemin == 40)
- | (mytimemin == 45)
- | (mytimemin == 50)
- | (mytimemin == 55)) {
- exactly(ON);
- } else {
- exactly(OFF);
- }
- if ((mytimemin == 1)
- | (mytimemin == 2)
- | (mytimemin == 6)
- | (mytimemin == 7)
- | (mytimemin == 11)
- | (mytimemin == 12)
- | (mytimemin == 16)
- | (mytimemin == 17)
- | (mytimemin == 21)
- | (mytimemin == 22)
- | (mytimemin == 26)
- | (mytimemin == 27)
- | (mytimemin == 31)
- | (mytimemin == 32)
- | (mytimemin == 36)
- | (mytimemin == 37)
- | (mytimemin == 41)
- | (mytimemin == 42)
- | (mytimemin == 46)
- | (mytimemin == 47)
- | (mytimemin == 51)
- | (mytimemin == 52)
- | (mytimemin == 56)
- | (mytimemin == 57)) {
- past(ON);
- } else {
- past(OFF);
- }
- if ((mytimemin == 3)
- | (mytimemin == 4)
- | (mytimemin == 8)
- | (mytimemin == 9)
- | (mytimemin == 13)
- | (mytimemin == 14)
- | (mytimemin == 18)
- | (mytimemin == 19)
- | (mytimemin == 23)
- | (mytimemin == 24)
- | (mytimemin == 28)
- | (mytimemin == 29)
- | (mytimemin == 33)
- | (mytimemin == 34)
- | (mytimemin == 38)
- | (mytimemin == 39)
- | (mytimemin == 43)
- | (mytimemin == 44)
- | (mytimemin == 48)
- | (mytimemin == 49)
- | (mytimemin == 53)
- | (mytimemin == 54)
- | (mytimemin == 58)
- | (mytimemin == 59)) {
- near(ON);
- } else {
- near(OFF);
- }
- //calculate minutes on the hour
- if(mytimemin<3){
- quarter(OFF);
- twenty(OFF);
- mten(OFF);
- mfive(OFF);
- half(OFF);
- to(OFF);
- past2(OFF);
- }
- // do nothing, no minutes it's on the hour
- if(mytimemin>2 && mytimemin<8){
- quarter(OFF);
- twenty(OFF);
- mten(OFF);
- mfive(ON);
- half(OFF);
- to(OFF);
- past2(ON);
- }
- if(mytimemin>7 && mytimemin<13){
- quarter(OFF);
- twenty(OFF);
- mten(ON);
- mfive(OFF);
- half(OFF);
- to(OFF);
- past2(ON);
- }
- if(mytimemin>12 && mytimemin<18){
- quarter(ON);
- twenty(OFF);
- mten(OFF);
- mfive(OFF);
- half(OFF);
- to(OFF);
- past2(ON);
- }
- if(mytimemin>17 && mytimemin<23){
- quarter(OFF);
- twenty(ON);
- mten(OFF);
- mfive(OFF);
- half(OFF);
- to(OFF);
- past2(ON);
- }
- if(mytimemin>22 && mytimemin<28){
- quarter(OFF);
- twenty(ON);
- mten(OFF);
- mfive(ON);
- half(OFF);
- to(OFF);
- past2(ON);
- }
- if(mytimemin>27 && mytimemin<33){
- quarter(OFF);
- twenty(OFF);
- mten(OFF);
- mfive(OFF);
- half(ON);
- to(OFF);
- past2(ON);
- }
- if(mytimemin>32 && mytimemin<38){
- quarter(OFF);
- twenty(ON);
- mten(OFF);
- mfive(ON);
- half(OFF);
- to(ON);
- past2(OFF);
- }
- if(mytimemin>37 && mytimemin<43){
- quarter(OFF);
- twenty(ON);
- mten(OFF);
- mfive(OFF);
- half(OFF);
- to(ON);
- past2(OFF);
- }
- if(mytimemin>42 && mytimemin<48){
- quarter(ON);
- twenty(OFF);
- mten(OFF);
- mfive(OFF);
- half(OFF);
- to(ON);
- past2(OFF);
- }
- if(mytimemin>47 && mytimemin<53){
- quarter(OFF);
- twenty(OFF);
- mten(ON);
- mfive(OFF);
- half(OFF);
- to(ON);
- past2(OFF);
- }
- if(mytimemin>52 && mytimemin<58){
- quarter(OFF);
- twenty(OFF);
- mten(OFF);
- mfive(ON);
- half(OFF);
- to(ON);
- past2(OFF);
- }
- // Calculate hour & oclocks
- if(mytimehr==1||mytimehr==13){
- if(mytimemin>32){
- one(OFF);
- two(ON);
- three(OFF);
- }
- else
- {
- one(ON);
- two(OFF);
- twelve(OFF);
- }
- }
- if(mytimehr==2||mytimehr==14){
- if(mytimemin>32){
- two(OFF);
- three(ON);
- four(OFF);
- }
- else
- {
- one(OFF);
- two(ON);
- three(OFF);
- }
- }
- if(mytimehr==3||mytimehr==15){
- if(mytimemin>32){
- three(OFF);
- four(ON);
- five(OFF);
- }
- else
- {
- two(OFF);
- three(ON);
- four(OFF);
- }
- }
- if(mytimehr==4||mytimehr==16){
- if(mytimemin>32){
- four(OFF);
- five(ON);
- six(OFF);
- }
- else
- {
- three(OFF);
- four(ON);
- five(OFF);
- }
- }
- if(mytimehr==5||mytimehr==17){
- if(mytimemin>32){
- five(OFF);
- six(ON);
- seven(OFF);
- }
- else
- {
- four(OFF);
- five(ON);
- six(OFF);
- }
- }
- if(mytimehr==6||mytimehr==18){
- if(mytimemin>32){
- six(OFF);
- seven(ON);
- eight(OFF);
- }
- else
- {
- five(OFF);
- six(ON);
- seven(OFF);
- }
- }
- if(mytimehr==7||mytimehr==19){
- if(mytimemin>32){
- seven(OFF);
- eight(ON);
- nine(OFF);
- }
- else
- {
- six(OFF);
- seven(ON);
- eight(OFF);
- }
- }
- if(mytimehr==8||mytimehr==20){
- if(mytimemin>32){
- eight(OFF);
- nine(ON);
- ten(OFF);
- }
- else
- {
- seven(OFF);
- eight(ON);
- nine(OFF);
- }
- }
- if(mytimehr==9||mytimehr==21){
- if(mytimemin>32){
- nine(OFF);
- ten(ON);
- eleven(OFF);
- }
- else
- {
- eight(OFF);
- nine(ON);
- ten(OFF);
- }
- }
- if(mytimehr==10||mytimehr==22){
- if(mytimemin>32){
- ten(OFF);
- eleven(ON);
- twelve(OFF);
- }
- else
- {
- nine(OFF);
- ten(ON);
- eleven(OFF);
- }
- }
- if(mytimehr==11||mytimehr==23){
- if(mytimemin>32){
- one(OFF);
- eleven(OFF);
- twelve(ON);
- }
- else
- {
- ten(OFF);
- eleven(ON);
- twelve(OFF);
- }
- }
- if(mytimehr==12||mytimehr==24){
- if(mytimemin>32){
- one(ON);
- two(OFF);
- twelve(OFF);
- }
- else
- {
- one(OFF);
- eleven(OFF);
- twelve(ON);
- }
- }
- }
- void loop (){
- DateTime now = rtc.now();
- mytimemonth=now.month();
- mytimeday=now.day();
- mytimehr=now.hour();
- mytimemin=now.minute();
- mytimesec=now.second();
- displayClock(); //function at bottom
- animations.UpdateAnimations();
- strip.Show();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement