Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 4.
- #include <virtuabotixRTC.h>
- #include <Adafruit_NeoPixel.h>
- #include "DHT.h"
- #define buttonPlus A1
- #define buttonMinus A2
- #define PLUS 9
- #define GND 11
- // Creation of the Real Time Clock Object
- // SCLK(CLK) -> 6, I/O(DAT) -> 7, CE(RST) -> 8
- virtuabotixRTC myRTC(6, 7, 8);
- //virtuabotixRTC myRTC(2, 3, 4);
- #define NUMPIXELS 24
- #define PIN 5
- Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
- // DHT11 Defines
- #define DHTPIN 4
- #define DHTTYPE DHT11
- #define TEMPPIXELS 6
- #define TEMPPIN 3
- DHT dht(DHTPIN, DHTTYPE);
- Adafruit_NeoPixel TEMPpixels = Adafruit_NeoPixel(TEMPPIXELS, TEMPPIN, NEO_GRB + NEO_KHZ800);
- unsigned long debounceDelay=50; // the debounce time; increase if the output flickers
- unsigned long longPressDelay=1000; // A gombokhoz tartozó hosszú megnyomás
- unsigned long repeatDelay=400; // A gombokhoz tartozó ismétlődés ideje
- signed long repeatDelayDynamic=400;
- signed long dynamic=10;
- unsigned long lastDebounceTime1=0, lastDebounceTime2=0;
- unsigned long counter=0;
- bool readingButton1, readingButton2, readingButton3, readingButton4, readingButton5;
- bool buttonShort1=false, buttonShort2=false, buttonShort3=false, buttonShort4=false, buttonShort5=false;
- bool buttonLong1=false, buttonLong2=false, buttonLong3=false, buttonLong4=false, buttonLong5=false;
- bool repeat1=false, repeat2=false;
- int hourLEDs[4] = {4,10,16,22};
- int hourTensLEDs[2] = {5,11};
- int minuteLEDs[4] = {2,8,14,20};
- int minuteTensLEDs[3] = {3,9,15};
- int secondLEDs[4] = {0, 6, 12, 18};
- int secondsTensLEDs[3] = {1, 7, 13};
- char buffer[9] ="";
- int secs, mins, hrs;
- int sunit, munit, hunit;
- int sten, mten, hten;
- int sunittemp, stentemp, munittemp,mtentemp, hunittemp, htentemp;
- long currentMillis, previousMillis;
- int temp, humi;
- int temperatureArray[41][6]{
- {0,2,6,6,6,6}, //5
- {1,2,6,6,6,6}, //6
- {0,1,2,6,6,6}, //7
- {3,6,6,6,6,6}, //8
- {0,3,6,6,6,6}, //9
- {1,3,6,6,6,6}, //10
- {0,1,3,6,6,6}, //11
- {2,3,6,6,6,6}, //12
- {0,2,3,6,6,6}, //13
- {1,2,3,6,6,6}, //14
- {0,1,2,3,6,6}, //15
- {4,6,6,6,6,6}, //16
- {0,4,6,6,6,6}, //17
- {1,4,6,6,6,6}, //18
- {0,1,4,6,6,6}, //19
- {2,4,6,6,6,6}, //20
- {0,2,4,6,6,6}, //21
- {1,2,4,6,6,6}, //22
- {0,1,2,4,6,6}, //23
- {3,4,6,6,6,6}, //24
- {0,3,4,6,6,6}, //25
- {1,2,4,6,6,6}, //26
- {0,1,3,4,6,6}, //27
- {2,3,4,6,6,6}, //28
- {0,1,3,4,6,6}, //29
- {1,2,3,4,6,6}, //30
- {0,1,2,3,4,6}, //31
- {5,6,6,6,6,6}, //32
- {0,5,6,6,6,6}, //33
- {1,5,6,6,6,6}, //34
- {0,2,5,6,6,6}, //35
- {2,5,6,6,6,6}, //36
- {0,2,5,6,6,6}, //37
- {1,2,5,6,6,6}, //38
- {0,1,2,5,6,6}, //39
- {3,5,6,6,6,6}, //40
- {0,3,5,6,6,6}, //41
- {1,3,5,6,6,6}, //42
- {0,1,3,5,6,6}, //43
- {2,3,5,6,6,6}, //44
- {1,2,3,5,6,6} //45
- };
- int sunitArray[10][3]{
- {24,24,24},
- {0,24,24},
- {6,24,24},
- {0,6,24},
- {12,24,24},
- {0,12,24},
- {6,12,24},
- {0,6,12},
- {18,24,24},
- {0,18,24}
- };
- int stenArray[10][3]{
- {24,24,24},
- {1,24,24},
- {7,24,24},
- {1,7,24},
- {13,24,24},
- {1,13,24},
- {7,13,24},
- {1,7,13},
- {19,24,24},
- (1,19,24)
- };
- int munitArray[10][3]{
- {24,24,24},
- {2,24,24},
- {8,24,24},
- {2,8,24},
- {14,24,24},
- {2,14,24},
- {8,14,24},
- {2,8,14},
- {20,24,24},
- {2,20,24}
- };
- int mtenArray[10][3]{
- {24,24,24},
- {3,24,24},
- {9,24,24},
- {3,9,24},
- {15,24,24},
- {3,15,24},
- {9,15,24},
- {3,9,15},
- {21,24,24},
- {3,21,24}
- };
- int hunitArray[10][3]{
- {24,24,24},
- {4,24,24},
- {10,24,24},
- {4,10,24},
- {16,24,24},
- {4,16,24},
- {10,16,24},
- {4,10,16},
- {22,24,24},
- {4,22,24}
- };
- int htenArray[10][3]{
- {24,24,24},
- {5,24,24},
- {11,24,24},
- {5,11,24},
- {17,24,24},
- {5,17,24},
- {11,17,24},
- {5,11,17},
- {23,24,24},
- {5,23,24}
- };
- const int analogInPin = A0;
- int sensorValue = 0;
- int outputValue =0;
- void setup()
- {
- Serial.begin(115200);
- pinMode(buttonPlus, INPUT_PULLUP);
- pinMode(buttonMinus, INPUT_PULLUP);
- dht.begin();
- // seconds, minutes, hours, day of the week, day of the month, month, year
- // NOTE ... Use this for the inital time setting, once uploaded, comment the line below out and upload again
- // this prevent the time restting each time you restart the Arduino.
- // seconds, minutes, hours, day of the week, day of the month, month, year
- // myRTC.setDS1302Time(00, 28, 17, 7, 27, 3, 2016);
- pixels.begin();
- pixels.setBrightness(125);
- pixels.show();
- TEMPpixels.begin();
- TEMPpixels.setBrightness(100);
- TEMPpixels.show();
- int secs = myRTC.seconds;
- int sunittemp = secs % 10;
- int stentemp = secs / 10;
- int munittemp = mins % 10;
- int mtentemp = mins / 10;
- int hunittemp = hrs % 10;
- int htentemp = hrs / 10;
- pixels.setBrightness(128);
- }
- // seconds, minutes, hours, day of the week, day of the month, month, year
- // myRTC.setDS1302Time(00, 28, 17, 7, 27, 3, 2016);
- void timePlus(byte tOffset){
- secs = myRTC.seconds;
- mins = myRTC.minutes;
- hrs = myRTC.hours;
- secs=secs+tOffset;
- if (secs>=60){
- secs=secs-60;
- mins++;
- if(mins==60){
- hrs++;
- if(hrs==24){
- hrs=0;
- }
- }
- }
- myRTC.setDS1302Time(secs, mins, hrs, 7, 29, 5, 2022);
- }
- void timeMinus(byte tOffset){
- secs = myRTC.seconds;
- mins = myRTC.minutes;
- hrs = myRTC.hours;
- secs=secs-tOffset;
- if (secs<=-1){
- secs=secs+60;
- mins--;
- if(mins==-1){
- mins=59;
- hrs--;
- if(hrs==-1){
- hrs=23;
- }
- }
- }
- myRTC.setDS1302Time(secs, mins, hrs, 7, 29, 5, 2022);
- }
- void tick(){
- secs = myRTC.seconds;
- mins = myRTC.minutes;
- hrs = myRTC.hours;
- Serial.print(hrs);
- Serial.print(":");
- Serial.print(mins);
- Serial.print(":");
- Serial.print(secs);
- Serial.print(" Temperature: ");
- Serial.print(temp);
- Serial.print(" *C\t ");
- Serial.print("Humidity: ");
- Serial.print(humi);
- Serial.println(" %");
- }
- void loop(){
- currentMillis = millis();
- if (currentMillis - previousMillis >= 1000) { // Timer every 1 second due to display refresh
- previousMillis = currentMillis;
- tick();
- }
- buttonCheck1();
- buttonCheck2();
- if (buttonShort1==true and readingButton1==HIGH){
- buttonShort1=false;
- //Serial.println("Plus Short Press");
- //counter++;
- timePlus(1);
- //Serial.println(counter);
- }
- if (buttonLong1==true){
- buttonLong1=false;
- //Serial.println("Plus Long Press");
- //counter++;
- timePlus(5);
- //Serial.println(counter);
- }
- if (buttonShort2==true and readingButton2==HIGH){
- buttonShort2=false;
- //Serial.println("Minus Short Press");
- //counter--;
- timeMinus(1);
- //Serial.println(counter);
- }
- if (buttonLong2==true){
- buttonLong2=false;
- //Serial.println("Minus Long Press");
- //counter--;
- timeMinus(5);
- //Serial.println(counter);
- }
- sensorValue = analogRead(analogInPin);
- outputValue = map(sensorValue, 915, 1023, 75, 255);
- pixels.setBrightness(outputValue);
- pixels.show();
- myRTC.updateTime();
- secs = myRTC.seconds;
- mins = myRTC.minutes;
- hrs = myRTC.hours;
- sunit = secs % 10;
- munit = mins % 10;
- hunit = hrs % 10;
- sten = secs / 10;
- mten = mins / 10;
- hten = hrs / 10;
- if (sunit != sunittemp)
- {
- // Seconds Unit Itterator
- clearSecondUnits();
- for (int i = 0; i < 3; i++)
- {
- pixels.setPixelColor(sunitArray[sunit][i], pixels.Color(255,0,0));
- pixels.show();
- }
- sunittemp = sunit;
- }
- if (sten != stentemp)
- {
- if (sten >= 1 || sten == 0)
- {
- clearSecondTens();
- for (int i = 0; i < 3; i++)
- {
- pixels.setPixelColor(stenArray[sten][i], pixels.Color(255,0,0));
- pixels.show();
- }
- }
- stentemp = sten;
- UpdateTemperature();
- }
- //// Minutes
- // units
- if (munit != munittemp)
- {
- clearMinuteUnits();
- for (int i = 0; i < 3; i++)
- {
- pixels.setPixelColor(munitArray[munit][i], pixels.Color(0,255,0));
- pixels.show();
- }
- munittemp = munit;
- }
- // tens
- if (mten != mtentemp)
- {
- clearMinuteTens();
- for (int i = 0; i < 3; i++)
- {
- pixels.setPixelColor(mtenArray[mten][i], pixels.Color(0,255,0));
- pixels.show();
- // Serial.println(mins);
- }
- mtentemp = mten;
- }
- /// HOURS
- // units
- if (hunit != hunittemp)
- {
- clearHourUnits();
- for (int i = 0; i < 3; i++)
- {
- pixels.setPixelColor(hunitArray[hunit][i], pixels.Color(0,0,255));
- pixels.show();
- }
- hunittemp = hunit;
- }
- // tens
- if (hten != htentemp)
- {
- clearHourTens();
- for (int i = 0; i < 3; i++)
- {
- pixels.setPixelColor(htenArray[hten][i], pixels.Color(0,0,255));
- pixels.show();
- // Serial.println(mins);
- }
- htentemp = hten;
- }
- /// End loop
- }
- void clearSecondUnits()
- {
- for (int i = 0; i < (sizeof(secondLEDs) / sizeof(secondLEDs[0])); i++)
- {
- // Serial.println(i);
- pixels.setPixelColor(secondLEDs[i], 0);
- }
- }
- void clearSecondTens()
- {
- for (int i = 0; i < (sizeof(secondsTensLEDs) / sizeof(secondsTensLEDs[0])); i++)
- {
- pixels.setPixelColor(secondsTensLEDs[i], 0);
- }
- }
- void clearMinuteUnits()
- {
- for (int i = 0; i < (sizeof(minuteLEDs) / sizeof(minuteLEDs[0])); i++)
- {
- pixels.setPixelColor(minuteLEDs[i], 0);
- }
- }
- void clearMinuteTens()
- {
- for (int i = 0; i < (sizeof(minuteTensLEDs) / sizeof(minuteTensLEDs[0])); i++)
- {
- pixels.setPixelColor(minuteTensLEDs[i], 0);
- }
- }
- void clearHourUnits()
- {
- for (int i = 0; i < (sizeof(hourLEDs) / sizeof(hourLEDs[0])); i++)
- {
- pixels.setPixelColor(hourLEDs[i], 0);
- }
- }
- void clearHourTens()
- {
- for (int i = 0; i < (sizeof(hourTensLEDs) / sizeof(hourTensLEDs[0])); i++)
- {
- pixels.setPixelColor(hourTensLEDs[i], 0);
- }
- }
- void UpdateTemperature()
- {
- // Reading temperature or humidity takes about 250 milliseconds!
- // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
- // float h = dht.readHumidity();
- humi = dht.readHumidity();
- // Read temperature as Celsius (the default)
- // float t = dht.readTemperature();
- temp = dht.readTemperature();
- // Read temperature as Fahrenheit (isFahrenheit = true)
- // float f = dht.readTemperature(true);
- // int f = dht.readTemperature(true);
- // Check if any reads failed and exit early (to try again).
- if (isnan(humi) || isnan(temp)) {
- Serial.println("Failed to read from DHT sensor!");
- delay(500);
- return;
- }
- //Serial.print("Temperature: ");
- //Serial.print(t);
- //Serial.print(" *C\t ");
- //Serial.print("Humidity: ");
- //Serial.print(h);
- //Serial.println(" %");
- for (int j = 0; j < 6; j++)
- {
- TEMPpixels.setPixelColor(temperatureArray[temp - 5][j], pixels.Color(255,0,125));
- // Serial.println(t);
- // Serial.println(temperatureArray[t][j]);
- TEMPpixels.show();
- }
- }
- void buttonCheck1() {
- readingButton1 = digitalRead(buttonPlus);
- if (readingButton1==LOW){
- if (repeat1==false){
- if ((millis() - lastDebounceTime1) > debounceDelay) {
- buttonShort1=true;
- }
- if ((millis() - lastDebounceTime1) > longPressDelay) {
- //buttonLong1=true;
- buttonShort1=false;
- repeat1=true;
- }
- } //else {
- if (millis()-lastDebounceTime1>repeatDelayDynamic) {
- lastDebounceTime1=millis();
- buttonLong1=true;
- buttonShort1=false;
- repeatDelayDynamic=repeatDelayDynamic-dynamic;
- if (repeatDelayDynamic<10) repeatDelayDynamic=10;
- }
- }
- if (readingButton1==HIGH) {
- lastDebounceTime1=millis();
- repeat1==false;
- repeatDelayDynamic=repeatDelay;
- }
- }
- void buttonCheck2() {
- readingButton2 = digitalRead(buttonMinus);
- if (readingButton2==LOW){
- if (repeat2==false){
- if ((millis() - lastDebounceTime2) > debounceDelay) {
- buttonShort2=true;
- }
- if ((millis() - lastDebounceTime2) > longPressDelay) {
- //buttonLong2=true;
- buttonShort2=false;
- repeat2=true;
- }
- } //else {
- if (millis()-lastDebounceTime2>repeatDelayDynamic) {
- lastDebounceTime2=millis();
- buttonLong2=true;
- buttonShort2=false;
- repeatDelayDynamic=repeatDelayDynamic-dynamic;
- if (repeatDelayDynamic<10) repeatDelayDynamic=10;
- }
- }
- if (readingButton2==HIGH) {
- lastDebounceTime2=millis();
- repeat2==false;
- repeatDelayDynamic=repeatDelay;
- }
- }
- // END
RAW Paste Data
Copied