// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library
// Edited by Donghwa Jeong 2016-9-13 for Neopixel Clock with 170 LEDs
#include <Wire.h>
#include "RTClib.h"
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1
#define PIN 6
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 170
// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
// End of trinket special code
Serial.begin(57600);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
// 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(2016, 9, 13, 11, 25, 0));
}
pixels.begin(); // This initializes the NeoPixel library.
}
int hour = 9;
int minute = 30;
void loop() {
DateTime now = rtc.now();
hour = now.hour();
minute = now.minute();
// Serial.print(hour);
// Serial.print(':');
// Serial.println(minute);
//12시 30분
//1
for(int i=12;i<=17;i++){
pixels.setPixelColor(i, pixels.Color(255,0,0));
pixels.show();
}
for(int i=36;i<=41;i++){
pixels.setPixelColor(i, pixels.Color(255,0,0));
pixels.show();
}
//2
for(int i=(48);i<=77;i++){
pixels.setPixelColor(i, pixels.Color(255,0,0)); pixels.show();
}
pixels.setPixelColor(84,pixels.Color(255,0,0)); pixels.show();
pixels.setPixelColor(85,pixels.Color(255,0,0)); pixels.show();
//3
for(int i=92;i<=109;i++){
pixels.setPixelColor(i, pixels.Color(255,0,0)); pixels.show();
}
for(int i=116;i<=127;i++){
pixels.setPixelColor(i, pixels.Color(255,0,0)); pixels.show();
}
for(int i=128;i<=145;i++){
pixels.setPixelColor(i, pixels.Color(255,0,0));
pixels.show();
}
for(int i=152;i<=169;i++){
pixels.setPixelColor(i, pixels.Color(255,0,0));
pixels.show();
}
delay(5000);
pixels.clear();
for(int i=0;i<170;i++){
pixels.setPixelColor(i, pixels.Color(0,0,255));
delay(50);
pixels.show();
}
for(int i=0;i<170;i++){
pixels.setPixelColor(i, pixels.Color(255,0,0));
delay(50);
pixels.show();
}
for(int i=0;i<170;i++){
pixels.setPixelColor(i, pixels.Color(0,255,0));
delay(50);
pixels.show();
}
// for(int i=12;i<=17;i++){
// pixels.setPixelColor(i, pixels.Color(255,0,0));
// pixels.show();
// }
// for(int i=36;i<=41;i++){
// pixels.setPixelColor(i, pixels.Color(255,0,0));
// pixels.show();
// }
// delay(1000);
//displayDigit(hour/10,0);
// delay(1000);
// displayDigit(hour%10,42);
// delay(1000);
//
// displayDigit(minute/10,86);
// delay(1000);
// displayDigit(minute%10,128);
// delay(1000);
}
void displayDigit(int num, int pos) // num is number, pos is position
{
if(num == 0)
{
for(int i=(pos+0);i<=(pos+17);i++){
pixels.setPixelColor(i, pixels.Color(255,0,0));
pixels.show();
}
for(int i=(pos+24);i<=(pos+41);i++){
pixels.setPixelColor(i, pixels.Color(255,0,0));
pixels.show();
}
}
else if (num == 1)
{
for(int i=(pos+12);i<=(pos+17);i++){
pixels.setPixelColor(i, pixels.Color(255,0,0)); pixels.show();
}
for(int i=(pos+36);i<=(pos+41);i++){
pixels.setPixelColor(i, pixels.Color(255,0,0)); pixels.show();
}
}
else if (num == 2)
{
for(int i=(pos+6);i<=(pos+35);i++){
pixels.setPixelColor(i, pixels.Color(255,0,0)); pixels.show();
}
}
// case 3:
// for(int i=(pos+6);i<=(pos+23);i++){
// pixels.setPixelColor(i, pixels.Color(255,0,0)); pixels.show();
// }
// for(int i=(pos+30);i<=(pos+41);i++){
// pixels.setPixelColor(i, pixels.Color(255,0,0)); pixels.show();
// }
// break;
//
// case 4:
// for(int i=(pos+0);i<=(pos+5);i++){
// pixels.setPixelColor(i, pixels.Color(255,0,0)); pixels.show();
// }
// for(int i=(pos+12);i<=(pos+23);i++){
// pixels.setPixelColor(i, pixels.Color(255,0,0)); pixels.show();
// }
// for(int i=(pos+36);i<=(pos+41);i++){
// pixels.setPixelColor(i, pixels.Color(255,0,0)); pixels.show();
// }
// break;
//
// case 5:
// for(int i=(pos+0);i<=(pos+11);i++){
// pixels.setPixelColor(i, pixels.Color(255,0,0)); pixels.show();
// }
// for(int i=(pos+18);i<=(pos+23);i++){
// pixels.setPixelColor(i, pixels.Color(255,0,0)); pixels.show();
// }
// for(int i=(pos+30);i<=(pos+41);i++){
// pixels.setPixelColor(i, pixels.Color(255,0,0)); pixels.show();
// }
// break;
//
// case 6:
// for(int i=(pos+0);i<=(pos+11);i++){
// pixels.setPixelColor(i, pixels.Color(255,0,0)); pixels.show();
// }
// for(int i=(pos+18);i<=(pos+41);i++){
// pixels.setPixelColor(i, pixels.Color(255,0,0)); pixels.show();
// }
// break;
// case 7:
// for(int i=(pos+6);i<=(pos+17);i++){
// pixels.setPixelColor(i, pixels.Color(255,0,0)); pixels.show();
// }
// for(int i=(pos+36);i<=(pos+41);i++){
// pixels.setPixelColor(i, pixels.Color(255,0,0)); pixels.show();
// }
// break;
// case 8:
// for(int i=(pos+0);i<=(pos+41);i++){
// pixels.setPixelColor(i, pixels.Color(255,0,0)); pixels.show();
// }
// break;
// case 9:
// for(int i=(pos+0);i<=(pos+23);i++){
// pixels.setPixelColor(i, pixels.Color(255,0,0)); pixels.show();
// }
// for(int i=(pos+36);i<=(pos+41);i++){
// pixels.setPixelColor(i, pixels.Color(255,0,0)); pixels.show();
// }
// break;
}
최신댓글