#include <Arduino.h> #include <Wire.h> #include "RTClib.h" #if defined(ARDUINO_ARCH_SAMD) #define Serial SerialUSB #endif RTC_DS1307 rtc; bool fillter = true; #include <Adafruit_NeoPixel.h> #define PIN 6 #define NUMPIXELS 48 Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); void setup () { pixels.begin(); Serial.begin(57600); if (! rtc.begin()) { Serial.println("Couldn't find RTC"); while (1); } if (! rtc.isrunning()) { Serial.println("RTC is NOT running!"); rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); } attachInterrupt(0, timeView, RISING); } //네오픽셀의 동작 시작과 RTC 모듈의 실행, 인터럽트 설정 void loop () { rainbow(20); rainbowCycle(20); } //동작안할때의 무지개색 코드 void colorWipe(uint32_t c, uint8_t wait) { for (uint16_t i = 0; i < pixels.numPixels(); i++) { pixels.setPixelColor(i, c); pixels.show(); delay(wait); Serial.println("AAA"); } } //동작안할때의 무지개색 코드 함수1 void rainbow(uint8_t wait) { uint16_t i, j; for (j = 0; j < 256; j++) { for (i = 0; i < pixels.numPixels(); i++) { pixels.setPixelColor(i, Wheel((i + j) & 255)); } pixels.show(); delay(wait); Serial.println("AAA"); } } //동작안할때의 무지개색 코드 함수2 void rainbowCycle(uint8_t wait) { uint16_t i, j; for (j = 0; j < 256 * 5; j++) { // 5 cycles of all colors on wheel for (i = 0; i < pixels.numPixels(); i++) { pixels.setPixelColor(i, Wheel(((i * 256 / pixels.numPixels()) + j) & 255)); } pixels.show(); delay(wait); Serial.println("AAA"); } } //동작안할때의 무지개색 코드 함수3 uint32_t Wheel(byte WheelPos) { WheelPos = 255 - WheelPos; if (WheelPos < 85) { return pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3); } if (WheelPos < 170) { WheelPos -= 85; return pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3); } WheelPos -= 170; return pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0); Serial.println("AAA"); } //동작안할때의 무지개색 코드 함수4 void timeView() { if (fillter) { fillter = false; pixels.clear(); pixels.show(); Serial.println("BBB"); DateTime now = rtc.now(); int T_h = (((now.hour() % 12) * 2) + (now.minute() < 30 ? 0 : 1)); pixels.setPixelColor((T_h < 12 ? 6 + (6 - T_h) : 18 + (18 - T_h)) - 1, pixels.Color(84, 255, 84)); int T_m = (now.minute() / 2.5); pixels.setPixelColor((T_m < 12 ? 6 + (6 - T_m) : 18 + (18 - T_m)) + 23, pixels.Color(50, 50, 255)); pixels.show(); delay(3000); fillter = true; } } //센서에 입력이 들어왔을 때의 동작 (인터럽트 사용) |