Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <TFT_ILI9163C.h>
- #include<CountUpDownTimer.h>
- #define buttonHoursPin 3
- #define buttonMinPin 4
- #define buttonStartPin 5
- #define relay 14
- #define __CS 10
- #define __DC 9
- #define __RST 8
- #define BLACK 0x0000
- #define BLUE 0x001F
- #define RED 0xF800
- #define GREEN 0x07E0
- #define CYAN 0x07FF
- #define MAGENTA 0xF81F
- #define YELLOW 0xFFE0
- #define WHITE 0xFFFF
- TFT_ILI9163C tft = TFT_ILI9163C(__CS, __DC, __RST);
- CountUpDownTimer T(DOWN);
- // debounce button timer
- long lastDebounceTime = 0; // the last time the output pin was toggled
- const unsigned long debounceDelay = 250; // the debounce time; increase if the output flickers
- const unsigned long interval = 1000;
- unsigned long previousInterval = 0;
- unsigned int Hours = 0;
- unsigned int Min = 0;
- const unsigned int add_min = 5; // 5 min
- void setup()
- {
- Serial.begin(9600);
- pinMode(buttonHoursPin, INPUT_PULLUP);
- pinMode(buttonMinPin, INPUT_PULLUP);
- pinMode(buttonStartPin, INPUT_PULLUP);
- pinMode(relay, OUTPUT);
- digitalWrite(relay,LOW);
- tft.begin();
- tft.setRotation(3);
- tft.setTextSize(3);
- tft.setTextColor(GREEN);
- T.SetTimer(0,0,0); //start at X minute (USE FOR: DOWN ONLY)
- }
- void loop()
- {
- T.Timer(); // run the timer
- if ( (millis() - lastDebounceTime) > debounceDelay)
- {
- if (digitalRead(buttonHoursPin) == LOW)
- {
- Hours++;
- if (Hours >= 4) Hours=0;
- Serial.println(Hours);
- lastDebounceTime = millis();
- }
- if (digitalRead(buttonMinPin) == LOW)
- {
- Min = Min+add_min;
- if (Min >= 60) Min=0;
- Serial.println(Min);
- lastDebounceTime = millis();
- }
- if (digitalRead(buttonStartPin) == LOW)
- {
- T.SetTimer(Hours,Min,20);
- T.StartTimer();
- lastDebounceTime = millis();
- }
- }
- if (T.TimeHasChanged()) // this prevents the time from being constantly shown.
- {
- tft.setCursor(10,15);
- tft.clearScreen();
- tft.print(T.ShowHours());
- tft.print(":");
- tft.print(T.ShowMinutes());
- tft.print(":");
- tft.print(T.ShowSeconds());
- // This DOES NOT format the time to 0:0x when seconds is less than 10.
- // if you need to format the time to standard format, use the sprintf() function.
- }
- unsigned long currentInterval = millis();
- if (currentInterval - previousInterval >= interval)
- {
- previousInterval = currentInterval;
- if(T.ShowHours() > 0 && T.ShowMinutes() > 0 && T.ShowSeconds() > 0)
- {
- Serial.print("relay on :");
- }
- else
- {
- Serial.print("relay off :");
- }
- /* if (T.TimeHasChanged())
- {
- Serial.print("time change :");
- Serial.println(T.TimeHasChanged());
- }
- else
- {
- Serial.println("time not change");
- } */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement