2021. 7. 21. 03:45ㆍ카테고리 없음
아두이노 디지털 시계 만들기 코드정보
특히 요즘은 스마트폰이 있어서 아무도 시계를 사용하지 않고 들여다보지 않기 때문에 시계를 만드는 것이 조금 무관하게 들리겠지만, 일을 하거나 운동을 할 때 좋습니다. 그래서 나는 내 방에 아두이노 디지털 시계를 하나 만들기로 했습니다. 시계 모델을 찾으면서 수천 개의 디자인을 얻었지만 대부분 7세그먼트 디스플레이를 사용했고 7세그먼트 디스플레이를 사용하지 않고 독특하고 화려한 시계를 만들고 싶었습니다. 그래서 아두이노 프로미니와 RTC 모듈에 네오픽셀 LED를 사용하려고 합니다. 제가 만든 시계는 시간과 실내 온도를 보여주는 아주 간단한 시계인데 이 시계의 주된 특징은 자릿수의 색이 매분 변한다는 것입니다.
나만의 레인보우 시계 만들기
아두이노 10 세그먼트 레인보우 클럭이 작동
이 시계의 작동은 매우 간단하고 다른 디지털 시계와 유사합니다. 이 시계는 DS3231 RTC 모듈을 사용하여 현재 시간과 날짜를 가져오고 이 시간은 Arduino Pro Mini를 사용하여 Neo-Pixel LED에 표시됩니다. DS3231은 시간, 분, 초뿐 아니라 일, 월 및 연도 정보를 유지할 수 있는 저비용의 정확한 실시간 시계입니다. 모듈은 I2C 통신 프로토콜을 사용하여 아두이노 보드에 매우 쉽게 연결할 수 있습니다. 하지만, 아두이노와 RTC 모듈 간의 통신에 관한 한 코드는 그렇게 작고 쉽지 않습니다. 그러나 DS3231 RTC용 라이브러리는 이미 인터넷에서 찾을 수 있습니다. 이러한 라이브러리의 도움으로 우리는 현재 시간을 읽을 수 있고, 아두이노의 도움으로 우리는 어떤 종류의 디스플레이에도 그 시간을 표시할 수 있습니다. DS3231 RTC 모듈에는 온도 센서도 함께 제공되므로 온도 측정값도 얻을 수 있습니다.
10 세그먼트 레인보우 클럭 회로 다이어그램
아두이노 LED 시계 구축을 위한 전체 도식은 아래 이미지에 참조
보시는 것처럼 회로도는 두 부분으로 나뉘는데, 첫 번째 회로는 아두이노 프로 미니, DS3231 RTC 모듈, 푸시 버튼, AMS1117 전압 조절기로 구성된 메인 회로이고, 두 번째 회로는 네오픽셀 LED가 모두 시간을 표시하도록 배열된 LED 자릿수 회로입니다. DS3231은 RTC 모듈의 SCL 및 SDA 핀이 Arduino의 I2C 핀(A4 및 A5)에 연결되도록 I2C 통신 프로토콜에서 작동합니다. 푸시 버튼은 아두이노의 디지털 핀 2와 4에 연결됩니다. 이 전체 설정은 직렬로 연결된 두 개의 18650 셀에 의해 구동됩니다. 이러한 셀의 출력 전압은 약 7.4이므로 AMS11175V 전압 조절기를 사용하여 규제된 5V를 아두이노 프로미니 및 기타 구성 요소에 공급합니다.
전시할 부품을 3-D 프린팅합니다.
앞서 설명한 것처럼, 우리는 7-세그먼트 디스플레이를 사용하는 대신 Neo-Pixel LED를 사용하여 시간을 표시할 것입니다. 여기서 우리는 네오픽셀 LED를 숫자 형태와 표시 시간으로 배열할 수 있도록 부품을 3D 프린팅할 것입니다. 몇 시간 동안 생각하고 계산한 후, 저는 열 개의 세그먼트 숫자를 디자인했습니다. 디자인은 매우 단순하며, 각 세그먼트에는 네오 픽셀 LED용 슬롯이 있습니다. 나중에 이 슬롯에 Neo 픽셀 LED를 배치하겠습니다. 또한 두 번째 표시를 위해 두 개의 세그먼트를 디자인했습니다. 저는 Tinker CAD 소프트웨어의 모든 부품을 디자인했습니다. 작업이 완료되고 나면 제 디자인은 다음과 같습니다.
디자인에 만족한 후 STL 파일로 내보내고 프린터 설정에 따라 슬라이스하여 최종적으로 인쇄했습니다. STL 파일은 Thingiverse에서도 다운로드할 수 있으며, 이 파일을 사용하여 케이스를 인쇄할 수 있습니다.
3D 프린팅 부품에서 Neo-Pixel LED를 조립합니다.
부품을 3D 프린팅한 후 먼저 네오픽셀 LED를 각각의 소켓에 삽입해야 합니다. Neo-픽셀 LED에는 VCC, GND, Data IN 및 Data Out의 핀이 4개 있습니다. Neo-픽셀 LED를 제어하려면 신호를 din 핀에 공급해야 합니다. Data OUT 핀을 다음 LED의 Data IN 핀에 연결하여 여러 개의 LED를 연결할 수 있습니다. 여기서 WS2812 Neo-픽셀을 소켓에 삽입합니다. 10개 세그먼트에 대해 동일한 작업을 수행하고 LED를 동일한 방향으로 배치해야 합니다. LED를 놓고 납땜을 시작하겠습니다. 먼저 LED 10개의 모든 접지를 함께 납땜합니다. 이를 위해 저는 단가닥 구리선을 사용하고 있습니다. 납땜하기 전에 각 LED의 핀을 확인하십시오. 또한 LED에 열을 가하지 마십시오. 모든 접지를 연결한 후, 이제 모든 VCC 핀을 함께 연결하겠습니다. 다음으로, 첫 번째 데이터를 다음 LED의 핀에 있는 데이터에 연결합니다. 10개의 모든 LED에 대해 이 과정을 반복합니다. 납땜을 모두 마치면 공통 접지, 공통 5V, 첫 번째 LED에 대한 연결 데이터, 마지막 LED의 전선 데이터가 나옵니다. 나머지 3자리 숫자도 이 과정을 반복해야 합니다. 또한 두 번째 세그먼트에 두 개의 LED를 삽입하고 납땜합니다. 모든 숫자와 두 번째 세그먼트를 연결한 후, 숫자를 서로 연결해 보겠습니다. 첫 번째 자리(왼쪽에서) 데이터를 두 번째 자리의 딘에 연결한 다음 두 번째 자리 데이터를 세 번째 자리의 딘에 연결한 다음 마지막으로 마지막 자리 데이터를 두 번째 세그먼트의 데이터에 연결합니다. 5V를 모두 연결하고 접지도 연결합니다. 그게 다예요, 이제 우리는 공통의 땅, 공통의 5V, 그리고 소음도 있어요.
Perf Board에 회로를 구성합니다.
브레드보드의 회로를 테스트한 후 퍼프보드에서 영구적으로 납땜하기로 결정했습니다. 크기를 줄이기 위해 회로를 최대한 작게 만들려고 했습니다. 먼저 작은 퍼프 보드를 가져간 다음 RTC 모듈용 여성 헤더 핀과 아두이노 프로 미니를 배치했습니다. 다음으로, 저는 작은 퍼프 보드에 푸시 버튼을 놓고 퍼프 보드에 핀을 납땜했습니다. 그리고 플렉시블 와이어의 도움으로 메인 PCB에 푸시버튼을 부착했습니다.
10개 세그먼트 레인보우 클럭용 엔클로저를 구축합니다.
이게 제일 어려운 게 아니에요. 인클로저를 3D 프린팅하거나 직접 만들 수 있습니다. 그래서 먼저 숫자의 길이와 폭을 쟀습니다. 측정 후 5mm MDF 보드를 가지고 길이 18cm, 폭 6.5mm의 직사각형의 면을 그렸습니다. 나는 직사각형 구조물을 만들고 그 안에 숫자를 넣을 계획입니다. 선을 그은 후 커터를 이용해 직사각형을 자르고 접합하여 앞면이 없는 직사각형 구조를 만들었습니다. 제작과 혼동되는 경우 이미지를 참조할 수 있습니다. 프레임을 만든 후 프레임에 숫자를 삽입하고 접착제로 고정했습니다. 프레임 뒷면에 메인 회로와 배터리를 고정했습니다. 그리고 푸시 버튼과 On/Off 스위치를 바깥쪽 뒷면에 배치했습니다. 숫자를 메인 회로와 연결한 후 뒷면을 닫았습니다. 마지막으로, 우리는 더 나은 빛의 확산을 위해 시계 전면에 플라스틱 시트를 부착해야 합니다. 모든 종류의 확산 플라스틱 시트를 사용할 수 있습니다.
Rainbow Clock용 Arduino Pro Mini를 프로그래밍합니다.
앞서 언급했듯이, 이 프로젝트의 코드는 그리 간단하지 않습니다. 솔직히 이 코드를 만들기 위해 다른 많은 시계 프로젝트들을 참고했습니다. 어쨌든 전체 코드는 문서 끝에 나와 있습니다. 여기서는 코드 전체를 한 줄씩 설명합니다.
우선, 저는 필수 도서관을 포함했습니다. 이 프로젝트에서는 DS3231 RTC 라이브러리를 사용하여 DS3232RTC 모듈을 제어합니다. DS3232RTC는 Maxim Integrated DS3232 및 DS3231 실시간 클럭을 지원하는 Arduino 라이브러리입니다. DS3232RTC 라이브러리는 DS3232 및 DS3231의 추가 기능을 지원하는 기능도 구현합니다. Time and Timeelib 라이브러리는 Arduino에 대한 시간 기록 기능을 제공합니다. 와이어 라이브러리를 사용하면 I2C(DS3231) 장치와의 통신이 가능합니다. 마지막으로 네오픽셀 LED를 제어하기 위해 FastLED를 사용하고 있습니다.
#include <DS3232RTC.h>
#include <TimeLib.h>
#include <Time.h>
#include <Wire.h>
#include <FastLED.h>
다음으로 총 LED 수, LED 타입의 색상 순서, 데이터 입력을 위한 아두이노 핀, 푸시버튼 핀을 정의하였습니다.
#define NUM_LEDS 42
#define COLOR_ORDER RGB
#define LED_PIN 6
#define MIN_PIN 4
#define HUR_PIN 2
또한 숫자와 기호에 대한 바이트 배열을 만들었습니다. 각 숫자에 총 10개의 LED가 있으며, 각 배열은 각 문자를 나타내는 총 12자(0-9 숫자 + 도 기호 및 C 문자)입니다. 예를 들어 {1,1,0,1,1,1,1,1,1,1,1,1,1,1은 0을 표시하는 스테이지의 다른 모든 LED의 숫자 세그먼트 3과 세그먼트 8에 있는 0을 나타냅니다.
byte digits[12] [10] = {
{1,1,0,1,1,1,1,0,1,1},
{1,1,1,1,1,0,0,0,0,0},
{1,0,1,1,1,1,0,1,1,1},
{1,1,1,1,1,1,0,1,0,1},
{1,1,1,1,0,1,1,1,0,0},
{1,1,1,0,1,1,1,1,0,1},
{1,1,1,0,0,1,1,1,1,1},
{1,1,1,1,1,1,1,0,0,0},
{1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,0,0},
{1,1,1,1,1,1,1,1,0,0},
{0,0,1,1,1,1,1,1,0,0}};
다음으로 아이디어에 따라 커스터마이징할 수 있는 컬러 테이블을 정의했습니다.
long ColorTable[21] = {
CRGB::Amethyst, //white
CRGB::Aqua, //pink
CRGB::Blue, //Blue
CRGB::Chartreuse,// Gold
CRGB::DarkGreen, //Red
CRGB::DarkMagenta,//Aqua
CRGB::DarkOrange, // yellow green
CRGB::DeepPink, //Aqua
CRGB::Fuchsia, //Sea blue
CRGB::Gold, //Gold
CRGB::GreenYellow,//off white
CRGB::LightCoral,//white
CRGB::Tomato,//white
CRGB::Salmon,//Pure white
CRGB::Red,// Drak Green
CRGB::Orchid,//blue white
CRGB::Sienna,//yellow white
CRGB::Purple,// aqua
CRGB::DarkOrange,//yellow green
CRGB::FloralWhite,//white
CRGB::Yellow //yellow
};
먼저 설정 섹션에서 시리얼 모니터와 시리얼을 사용한 I2C 통신을 시작했습니다.begin(시작)과 wire(전선)를 각각 시작합니다. 여기서는 코드와 회로를 테스트하기 위해 직렬 모니터를 사용합니다. 또한 나는 우리가 사용하고 있는 모든 핀의 모드를 출력과 같이 입력과 데이터 핀으로 정의하였고 입력의 경우 입력 풀업 기능을 사용하여 하이 핀 상태를 풀링했습니다.
void setup(){
Serial.begin(9600);
Wire.begin();
FastLED.addLeds<WS2812B, LED_PIN, RGB>(leds, NUM_LEDS);
pinMode(DST_PIN, INPUT_PULLUP);
pinMode(MIN_PIN, INPUT_PULLUP);
pinMode(HUR_PIN, INPUT_PULLUP);
}
그런 다음 RTC.read 기능을 사용하여 시간을 읽어 DateTime 객체에 저장했습니다. 또한 24시간 포맷을 12시간 포맷으로 변환했습니다.
GetTime(){
tmElements_t Now;
RTC.read(Now);
int hour=Now.Hour;
int minute=Now.Minute;
int second =Now.Second;
if (second % 2==0)
{Dot = false;}
else {Dot = true;};
if (hour >= 12) {
hour -= 12;
}
다음으로, 디스플레이에 현재 시간과 온도를 표시하기 위해 어레이를 배열하고 배열할 수 있는 두 개의 어레이를 정의했습니다. 마지막 자리 LED부터 시작해서 네 자리 표시했습니다. 저는 커서 기능을 사용하여 각 자릿수의 첫 번째 LED를 정의했습니다. 같은 방법으로 온도도 표시했습니다.
for(int i=1;i<=4;i++){
int digit = Now % 10;
if (i==1){
cursor = 30;
for(int k=0; k<=9;k++){
if (digits[digit][k]== 1){leds[cursor]=ledColor;}
else if (digits[digit][k]==0){leds[cursor]=0x000000;}
cursor ++
};
void time 기능에서는 시간을 설정할 수 있습니다. 여기서는 아두이노의 디지털 읽기 기능을 사용하여 푸시버튼의 상태를 읽었습니다.
void TimeAdjust(){
int buttonH = digitalRead(HUR_PIN);
int buttonM = digitalRead(MIN_PIN);
if (buttonH == LOW || buttonM == LOW){
delay(500);
tmElements_t Now;
RTC.read(Now);
int hour=Now.Hour;
int minutes=Now.Minute;
int second =Now.Second;
if (buttonH == LOW){
if (Now.Hour== 23){Now.Hour=0;}
else {Now.Hour += 1;};
}else {
if (Now.Minute== 59){Now.Minute=0;}
else {Now.Minute += 1;};
};
RTC.write(Now);
}
마지막으로 메인 루프 부분에서 먼저 시간 수정 여부를 확인했습니다. 그리고 시간에 맞게 LED 배열을 업데이트했습니다. 온도 조절 장치도 마찬가지예요 마지막으로 빠른 LED를 사용하여 값을 숫자로 표시했습니다.기능을 표시합니다.
Void loop() {
BrightnessCheck();
DSTcheck();
TimeAdjust();
TimeToArray();
TempToArray();
FastLED.show();
if (TempShow == true)
delay (8000);
}
}
10개 세그먼트 레인보우 시계를 테스트합니다.
네오픽셀 LED와 회로를 조립했습니다. 이제 시계를 시험해 볼 시간입니다. 그러기 위해서는 아두이노를 노트북에 연결하고 코드를 업로드하세요.
이 시계 프로젝트가 마음에 들었기를 바랍니다. 전체 메이킹 영상은 아래와 같습니다. 질문이 있으시면 아래 댓글란에 남겨주시기 바랍니다.
#include <DS3232RTC.h>
#include <TimeLib.h>
#include <Time.h>
#include <Wire.h>
#include <FastLED.h>
#define NUM_LEDS 42
#define COLOR_ORDER RGB // Define color order for your strip
#define LED_PIN 6 // Data pin for led comunication
#define DST_PIN 5 // Define DST adjust button pin
#define MIN_PIN 4 // Define Minutes adjust button pin
#define HUR_PIN 2 // Define Hours adjust button pin
#define BRI_PIN 3 // Define Light sensor pin
CRGB leds[NUM_LEDS];
byte digits[12][10] = {
{1,1,0,1,1,1,1,0,1,1},
{1,1,1,1,1,0,0,0,0,0},
{1,0,1,1,1,1,0,1,1,1},
{1,1,1,1,1,1,0,1,0,1},
{1,1,1,1,0,1,1,1,0,0},
{1,1,1,0,1,1,1,1,0,1},
{1,1,1,0,0,1,1,1,1,1},
{1,1,1,1,1,1,1,0,0,0},
{1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,0,0},
{1,1,1,1,1,1,1,1,0,0},
{0,0,1,1,1,1,1,1,0,0}};
bool Dot = true; //Dot state
bool DST = true; //DST state// false to true
bool TempShow = false;
int last_digit = 0;
// int ledColor = 0x0000FF; // Color used (in hex)
long ledColor = CRGB::DarkOrchid; // Color used (in hex)
//long ledColor = CRGB::MediumVioletRed;
//Random colors i picked up
long ColorTable[21] = {
CRGB::Amethyst, //white
CRGB::Aqua, //pink
CRGB::Blue, //Blue
CRGB::Chartreuse,// Gold
CRGB::DarkGreen, //Red
CRGB::DarkMagenta,//Aqua
CRGB::DarkOrange, // yellow green
CRGB::DeepPink, //Aqua
CRGB::Fuchsia, //Sea blue
CRGB::Gold, //Gold
CRGB::GreenYellow,//off white
CRGB::LightCoral,//white
CRGB::Tomato,//white
CRGB::Salmon,//Pure white
CRGB::Red,// Drak Green
CRGB::Orchid,//blue white
CRGB::Sienna,//yellow white
CRGB::Purple,// aqua
CRGB::DarkOrange,//yellow green
CRGB::FloralWhite,//white
CRGB::Yellow //yellow
};
void setup(){
Serial.begin(9600);
Wire.begin();
FastLED.addLeds<WS2812B, LED_PIN, RGB>(leds, NUM_LEDS);
LEDS.setBrightness(75); // Set initial brightness
pinMode(DST_PIN, INPUT_PULLUP); // Define DST adjust button pin
pinMode(MIN_PIN, INPUT_PULLUP); // Define Minutes adjust button pin
pinMode(HUR_PIN, INPUT_PULLUP); // Define Hours adjust button pin
pinMode(BRI_PIN, INPUT_PULLUP); // Define bright adjust
TempShow = false; // do not show temperature
}
// Get time in a single number, if hours will be a single digit then time will be displayed 155 instead of 0155
int GetTime(){
tmElements_t Now;
RTC.read(Now);
//time_t Now = RTC.Now();// Getting the current Time and storing it into a DateTime object
int hour=Now.Hour;
int minute=Now.Minute;
int second =Now.Second;
if (second % 2==0)
{Dot = false;}
else {Dot = true;};
if (hour >= 12) {
hour -= 12;
}
// Handle hour 0 (midnight) being shown as 12.
// else if (hour == 0) {
// hour += 12;
// }
return (hour*100+minute);
};
// Check Light sensor and set brightness accordingly
void BrightnessCheck(){
const byte sensorPin = 3; // light sensor pin
const byte brightnessLow = 75; // Low brightness value
const byte brightnessHigh = 20; // High brightness value
int sensorValue = digitalRead(sensorPin); // Read sensor
if (sensorValue == 0) {LEDS.setBrightness(brightnessHigh);}
else {LEDS.setBrightness(brightnessLow);}
};
// Convert time to array needed for display
void TimeToArray(){
int Now = GetTime(); // Get time
int cursor = 42; // last led number
// Serial.print("Time is: ");Serial.println(Now);
if (DST){ // if DST is true then add one hour
Now+=100;
// Serial.print("DST is ON, time set to : ");Serial.println(Now);
};
if (Dot){leds[40]=ledColor;
leds[41]=ledColor;}
else {leds[40]=0x000000;
leds[41]=0x000000;
};
for(int i=1;i<=4;i++){
int digit = Now % 10; // get last digit in time
if (i==1){
// Serial.print("Digit 4 is : ");Serial.print(digit);Serial.print(" ");
cursor = 30;
for(int k=0; k<=9;k++){
// Serial.print(digits[digit][k]);
if (digits[digit][k]== 1){leds[cursor]=ledColor;}
else if (digits[digit][k]==0){leds[cursor]=0x000000;};
cursor ++;
};
// Serial.println();
if (digit != last_digit)
{
cylon();
ledColor = ColorTable[random(21)];
}
last_digit = digit;
}
else if (i==2){
// Serial.print("Digit 3 is : ");Serial.print(digit);Serial.print(" ");
cursor =20;
for(int k=0; k<=9;k++){
// Serial.print(digits[digit][k]);
if (digits[digit][k]== 1){leds[cursor]=ledColor;}
else if (digits[digit][k]==0){leds[cursor]=0x000000;};
cursor ++;
};
// Serial.println();
}
else if (i==3){
// Serial.print("Digit 2 is : ");Serial.print(digit);Serial.print(" ");
cursor =10;
for(int k=0; k<=9;k++){
// Serial.print(digits[digit][k]);
if (digits[digit][k]== 1){leds[cursor]=ledColor;}
else if (digits[digit][k]==0){leds[cursor]=0x000000;};
cursor ++;
};
// Serial.println();
}
else if (i==4){
// Serial.print("Digit 1 is : ");Serial.print(digit);Serial.print(" ");
cursor =0;
if(digit !=0){
for(int k=0; k<=9;k++){
// Serial.print(digits[digit][k]);
if (digits[digit][k]== 1){leds[cursor]=ledColor;}
else if (digits[digit][k]==0){leds[cursor]=0x000000;};
cursor ++;
};
}
if(digit ==0){
for(int k=0; k<=9;k++){
// Serial.print(digits[digit][k]);
if (digits[12][k]== 1){leds[cursor]=ledColor;}
else if (digits[12][k]==0){leds[cursor]=0x000000;};
cursor ++;
};
// Serial.println();
}
}
Now /= 10;
};
};
// Convert temp to array needet for display
void TempToArray(){
tmElements_t tm;
RTC.read(tm);
if (tm.Second != 27) {
TempShow = false;
return;
}
TempShow = false;//true to false
int t = RTC.temperature();
int celsius = (t / 4.0) * 100;
Serial.print("Temp is: ");Serial.println(celsius);
int cursor = 42; // last led number
leds[40]=0x000000;
leds[41]=0x000000;
for(int i=1;i<=4;i++){
int digit = celsius % 10; // get last digit in time
if (i==1){
Serial.print("Digit 4 is : ");Serial.print(digit);Serial.print(" ");
cursor = 30;
for(int k=0; k<=9;k++){
Serial.print(digits[11][k]);
if (digits[11][k]== 1){leds[cursor]=ledColor;}
else if (digits[11][k]==0){leds[cursor]=0x000000;};
cursor ++;
};
Serial.println();
}
else if (i==2){
Serial.print("Digit 3 is : ");Serial.print(digit);Serial.print(" ");
cursor =20;
for(int k=0; k<=9;k++){
Serial.print(digits[10][k]);
if (digits[10][k]== 1){leds[cursor]=ledColor;}
else if (digits[10][k]==0){leds[cursor]=0x000000;};
cursor ++;
};
Serial.println();
}
else if (i==3){
Serial.print("Digit 2 is : ");Serial.print(digit);Serial.print(" ");
cursor =10;
for(int k=0; k<=9;k++){
Serial.print(digits[digit][k]);
if (digits[digit][k]== 1){leds[cursor]=ledColor;}
else if (digits[digit][k]==0){leds[cursor]=0x000000;};
cursor ++;
};
Serial.println();
}
else if (i==4){
Serial.print("Digit 1 is : ");Serial.print(digit);Serial.print(" ");
cursor =0;
for(int k=0; k<=9;k++){
Serial.print(digits[digit][k]);
if (digits[digit][k]== 1){leds[cursor]=ledColor;}
else if (digits[digit][k]==0){leds[cursor]=0x000000;};
cursor ++;
};
Serial.println();
}
celsius /= 10;
};
};
void DSTcheck(){
int buttonDST = digitalRead(DST_PIN);
// Serial.print("DST is: ");Serial.println(DST);
if (buttonDST == LOW){
if (DST){
DST=false;
// Serial.print("Switching DST to: ");Serial.println(DST);
}
else if (!DST){
DST=true;
// Serial.print("Switching DST to: ");Serial.println(DST);
};
delay(500);
};
}
void TimeAdjust(){
int buttonH = digitalRead(HUR_PIN);
int buttonM = digitalRead(MIN_PIN);
if (buttonH == LOW || buttonM == LOW){
delay(500);
tmElements_t Now;
RTC.read(Now);
int hour=Now.Hour;
int minutes=Now.Minute;
int second =Now.Second;
if (buttonH == LOW){
if (Now.Hour== 23){Now.Hour=0;}
else {Now.Hour += 1;};
}else {
if (Now.Minute== 59){Now.Minute=0;}
else {Now.Minute += 1;};
// if (Now.Hour > 12){Now.Hour = Now.Hour -12;} // 24 to 12 hr
// else {Now.Hour = Now.Hour ;};
};
RTC.write(Now);
}
}
/* coool effect function*/
void fadeall() { for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(250); } }
void cylon () {
static uint8_t hue = 0;
Serial.print("x");
// First slide the led in one direction
for(int i = 0; i < NUM_LEDS; i++) {
// Set the i'th led to red
leds[i] = CHSV(hue++, 255, 255);
// Show the leds
FastLED.show();
// now that we've shown the leds, reset the i'th led to black
// leds[i] = CRGB::Black;
fadeall();
// Wait a little bit before we loop around and do it again
delay(10);
}
Serial.print("x");
// Now go in the other direction.
for(int i = (NUM_LEDS)-1; i >= 0; i--) {
// Set the i'th led to red
leds[i] = CHSV(hue++, 255, 255);
// Show the leds
FastLED.show();
// now that we've shown the leds, reset the i'th led to black
// leds[i] = CRGB::Black;
fadeall();
// Wait a little bit before we loop around and do it again
delay(10);
}
}
void loop() // Main loop
{
BrightnessCheck(); // Check brightness
DSTcheck(); // Check DST
TimeAdjust(); // Check to se if time is geting modified
TimeToArray(); // Get leds array with required configuration
TempToArray(); // Show Temperature
FastLED.show(); // Display leds array
if (TempShow == true)
delay (8000);
}