#include <Wire.h>
#include <Adafruit_NeoPixel.h>
#define PIN 7
Adafruit_NeoPixel strip = Adafruit_NeoPixel(42, PIN, NEO_GRB + NEO_KHZ800);
const byte DS1307 = 0x68;
const byte NumberOfFields = 7;
byte ss, mm, hh, d, w, m, y, R, G, B;
int n, an;
void setup()
{
Wire.begin();
//setTime(22, 46, 00, 1, 23, 5, 21); // 12:30:45 CN 08-02-201
Serial.begin(115200);
strip.begin();
strip.show();
}
void loop()
{
for (int i = 0; i < 1536; i++)
{
an = map(analogRead (A1), 0, 1023, 0, 255);
readDS1307();
//digitalClockDisplay();
showRGB(i);
//Serial.print(R/100); Serial.print(R/10%10); Serial.print(R%10); Serial.print(" ");
//Serial.print(G/100); Serial.print(G/10%10); Serial.print(G%10); Serial.print(" ");
//Serial.print(B/100); Serial.print(B/10%10); Serial.print(B%10); Serial.print(" "); Serial.println(i);
switch (hh/10)
{
case 0: {strip.setPixelColor(0, 0, 0, 0); strip.setPixelColor(1, 0, 0, 0);}; break;
case 1: {strip.setPixelColor(0, 0, 0, 0); strip.setPixelColor(1, R, G, B);}; break;
case 2: {strip.setPixelColor(0, R, G, B); strip.setPixelColor(1, 0, 0, 0);}; break;
}
showRGB((i+an*1)%1536);
switch (hh%10)
{
case 0: {strip.setPixelColor(2, 0, 0, 0); strip.setPixelColor(3, 0, 0, 0); strip.setPixelColor(4, 0, 0, 0); strip.setPixelColor(5, 0, 0, 0);}; break;
case 1: {strip.setPixelColor(2, 0, 0, 0); strip.setPixelColor(3, 0, 0, 0); strip.setPixelColor(4, 0, 0, 0); strip.setPixelColor(5, R, G, B);}; break;
case 2: {strip.setPixelColor(2, 0, 0, 0); strip.setPixelColor(3, 0, 0, 0); strip.setPixelColor(4, R, G, B); strip.setPixelColor(5, 0, 0, 0);}; break;
case 3: {strip.setPixelColor(2, 0, 0, 0); strip.setPixelColor(3, 0, 0, 0); strip.setPixelColor(4, R, G, B); strip.setPixelColor(5, R, G, B);}; break;
case 4: {strip.setPixelColor(2, 0, 0, 0); strip.setPixelColor(3, R, G, B); strip.setPixelColor(4, 0, 0, 0); strip.setPixelColor(5, 0, 0, 0);}; break;
case 5: {strip.setPixelColor(2, 0, 0, 0); strip.setPixelColor(3, R, G, B); strip.setPixelColor(4, 0, 0, 0); strip.setPixelColor(5, R, G, B);}; break;
case 6: {strip.setPixelColor(2, 0, 0, 0); strip.setPixelColor(3, R, G, B); strip.setPixelColor(4, R, G, B); strip.setPixelColor(5, 0, 0, 0);}; break;
case 7: {strip.setPixelColor(2, 0, 0, 0); strip.setPixelColor(3, R, G, B); strip.setPixelColor(4, R, G, B); strip.setPixelColor(5, R, G, B);}; break;
case 8: {strip.setPixelColor(2, R, G, B); strip.setPixelColor(3, 0, 0, 0); strip.setPixelColor(4, 0, 0, 0); strip.setPixelColor(5, 0, 0, 0);}; break;
case 9: {strip.setPixelColor(2, R, G, B); strip.setPixelColor(3, 0, 0, 0); strip.setPixelColor(4, 0, 0, 0); strip.setPixelColor(5, R, G, B);}; break;
}
showRGB((i+an*2)%1536);
switch (mm/10)
{
case 0: {strip.setPixelColor(6, 0, 0, 0); strip.setPixelColor(7, 0, 0, 0); strip.setPixelColor(8, 0, 0, 0);}; break;
case 1: {strip.setPixelColor(6, 0, 0, 0); strip.setPixelColor(7, 0, 0, 0); strip.setPixelColor(8, R, G, B);}; break;
case 2: {strip.setPixelColor(6, 0, 0, 0); strip.setPixelColor(7, R, G, B); strip.setPixelColor(8, 0, 0, 0);}; break;
case 3: {strip.setPixelColor(6, 0, 0, 0); strip.setPixelColor(7, R, G, B); strip.setPixelColor(8, R, G, B);}; break;
case 4: {strip.setPixelColor(6, R, G, B); strip.setPixelColor(7, 0, 0, 0); strip.setPixelColor(8, 0, 0, 0);}; break;
case 5: {strip.setPixelColor(6, R, G, B); strip.setPixelColor(7, 0, 0, 0); strip.setPixelColor(8, R, G, B);}; break;
}
showRGB((i+an*3)%1536);
switch (mm%10)
{
case 0: {strip.setPixelColor(9, 0, 0, 0); strip.setPixelColor(10, 0, 0, 0); strip.setPixelColor(11, 0, 0, 0); strip.setPixelColor(12, 0, 0, 0);}; break;
case 1: {strip.setPixelColor(9, 0, 0, 0); strip.setPixelColor(10, 0, 0, 0); strip.setPixelColor(11, 0, 0, 0); strip.setPixelColor(12, R, G, B);}; break;
case 2: {strip.setPixelColor(9, 0, 0, 0); strip.setPixelColor(10, 0, 0, 0); strip.setPixelColor(11, R, G, B); strip.setPixelColor(12, 0, 0, 0);}; break;
case 3: {strip.setPixelColor(9, 0, 0, 0); strip.setPixelColor(10, 0, 0, 0); strip.setPixelColor(11, R, G, B); strip.setPixelColor(12, R, G, B);}; break;
case 4: {strip.setPixelColor(9, 0, 0, 0); strip.setPixelColor(10, R, G, B); strip.setPixelColor(11, 0, 0, 0); strip.setPixelColor(12, 0, 0, 0);}; break;
case 5: {strip.setPixelColor(9, 0, 0, 0); strip.setPixelColor(10, R, G, B); strip.setPixelColor(11, 0, 0, 0); strip.setPixelColor(12, R, G, B);}; break;
case 6: {strip.setPixelColor(9, 0, 0, 0); strip.setPixelColor(10, R, G, B); strip.setPixelColor(11, R, G, B); strip.setPixelColor(12, 0, 0, 0);}; break;
case 7: {strip.setPixelColor(9, 0, 0, 0); strip.setPixelColor(10, R, G, B); strip.setPixelColor(11, R, G, B); strip.setPixelColor(12, R, G, B);}; break;
case 8: {strip.setPixelColor(9, R, G, B); strip.setPixelColor(10, 0, 0, 0); strip.setPixelColor(11, 0, 0, 0); strip.setPixelColor(12, 0, 0, 0);}; break;
case 9: {strip.setPixelColor(9, R, G, B); strip.setPixelColor(10, 0, 0, 0); strip.setPixelColor(11, 0, 0, 0); strip.setPixelColor(12, R, G, B);}; break;
}
showRGB((i+an*4)%1536);
switch (ss/10)
{
case 0: {strip.setPixelColor(13, 0, 0, 0); strip.setPixelColor(14, 0, 0, 0); strip.setPixelColor(15, 0, 0, 0);}; break;
case 1: {strip.setPixelColor(13, 0, 0, 0); strip.setPixelColor(14, 0, 0, 0); strip.setPixelColor(15, R, G, B);}; break;
case 2: {strip.setPixelColor(13, 0, 0, 0); strip.setPixelColor(14, R, G, B); strip.setPixelColor(15, 0, 0, 0);}; break;
case 3: {strip.setPixelColor(13, 0, 0, 0); strip.setPixelColor(14, R, G, B); strip.setPixelColor(15, R, G, B);}; break;
case 4: {strip.setPixelColor(13, R, G, B); strip.setPixelColor(14, 0, 0, 0); strip.setPixelColor(15, 0, 0, 0);}; break;
case 5: {strip.setPixelColor(13, R, G, B); strip.setPixelColor(14, 0, 0, 0); strip.setPixelColor(15, R, G, B);}; break;
}
showRGB((i+an*5)%1536);
switch (ss%10)
{
case 0: {strip.setPixelColor(16, 0, 0, 0); strip.setPixelColor(17, 0, 0, 0); strip.setPixelColor(18, 0, 0, 0); strip.setPixelColor(19, 0, 0, 0);}; break;
case 1: {strip.setPixelColor(16, 0, 0, 0); strip.setPixelColor(17, 0, 0, 0); strip.setPixelColor(18, 0, 0, 0); strip.setPixelColor(19, R, G, B);}; break;
case 2: {strip.setPixelColor(16, 0, 0, 0); strip.setPixelColor(17, 0, 0, 0); strip.setPixelColor(18, R, G, B); strip.setPixelColor(19, 0, 0, 0);}; break;
case 3: {strip.setPixelColor(16, 0, 0, 0); strip.setPixelColor(17, 0, 0, 0); strip.setPixelColor(18, R, G, B); strip.setPixelColor(19, R, G, B);}; break;
case 4: {strip.setPixelColor(16, 0, 0, 0); strip.setPixelColor(17, R, G, B); strip.setPixelColor(18, 0, 0, 0); strip.setPixelColor(19, 0, 0, 0);}; break;
case 5: {strip.setPixelColor(16, 0, 0, 0); strip.setPixelColor(17, R, G, B); strip.setPixelColor(18, 0, 0, 0); strip.setPixelColor(19, R, G, B);}; break;
case 6: {strip.setPixelColor(16, 0, 0, 0); strip.setPixelColor(17, R, G, B); strip.setPixelColor(18, R, G, B); strip.setPixelColor(19, 0, 0, 0);}; break;
case 7: {strip.setPixelColor(16, 0, 0, 0); strip.setPixelColor(17, R, G, B); strip.setPixelColor(18, R, G, B); strip.setPixelColor(19, R, G, B);}; break;
case 8: {strip.setPixelColor(16, R, G, B); strip.setPixelColor(17, 0, 0, 0); strip.setPixelColor(18, 0, 0, 0); strip.setPixelColor(19, 0, 0, 0);}; break;
case 9: {strip.setPixelColor(16, R, G, B); strip.setPixelColor(17, 0, 0, 0); strip.setPixelColor(18, 0, 0, 0); strip.setPixelColor(19, R, G, B);}; break;
}
strip.show();
delayMicroseconds(map(analogRead(A0), 0, 1023, 10, 5000));
}
}
void readDS1307()
{
Wire.beginTransmission(DS1307); Wire.write((byte)0x00); Wire.endTransmission(); Wire.requestFrom(DS1307, NumberOfFields);
ss = bcd2dec(Wire.read() & 0x7f);
mm = bcd2dec(Wire.read());
hh = bcd2dec(Wire.read() & 0x3f);
w = bcd2dec(Wire.read());
d = bcd2dec(Wire.read());
m = bcd2dec(Wire.read());
y = bcd2dec(Wire.read());
}
int bcd2dec(byte num) {return ((num/16 * 10) + (num % 16));}
int dec2bcd(byte num) {return ((num/10 * 16) + (num % 10));}
void digitalClockDisplay() {printDigits(hh); Serial.print(":"); printDigits(mm); Serial.print(":"); printDigits(ss); Serial.print(", "); Serial.print(w); Serial.print(", "); Serial.print(d); Serial.print("/"); Serial.print(m); Serial.print("/"); Serial.print(y); Serial.println();}
void printDigits(int digits) {if (digits < 10) Serial.print('0'); Serial.print(digits);}
void setTime(byte hr, byte min, byte sec, byte wd, byte d, byte mth, byte yr) {Wire.beginTransmission(DS1307); Wire.write(byte(0x00)); Wire.write(dec2bcd(sec)); Wire.write(dec2bcd(min)); Wire.write(dec2bcd(hr)); Wire.write(dec2bcd(wd)); Wire.write(dec2bcd(d)); Wire.write(dec2bcd(mth)); Wire.write(dec2bcd(yr)); Wire.endTransmission();}
void showRGB(int color)
{
if (color <= 255)
{
R = color;
G = 0;
B = 255;
}
else if (color <= 511)
{
R = 255;
G = 0;
B = 511 - color;
}
else if (color <= 767)
{
R = 255;
G = color - 512;
B = 0;
}
else if (color <= 1023)
{
R = 1023 - color;
G = 255;
B = 0;
}
else if (color <= 1279)
{
R = 0;
G = 255;
B = color - 1024;
}
else
{
R = 0;
G = 1535 - color;
B = 255;
}
}