Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <RTClib.h>
- #include <TimerOne.h>
- RTC_DS1307 RTC;
- volatile int countM = 0;
- volatile int countH = 0;
- volatile boolean zcM = 0;
- volatile boolean zcH = 0;
- int potPin = A0;
- int buttonPin = A1;
- int handArr[] = {4, 5, 6, 11, 12, 13, 14, 15, 16, 17, 18, 19};
- int freqStep = 65;
- int hourPin = handArr[0];
- int hourBrightness = 0;
- int minutePin = handArr[0];
- int minuteBrightnessArr[] = {80, 65, 50, 35, 20};
- int minuteBrightness = minuteBrightnessArr[0];
- int dim = 1;
- void setup()
- {
- Serial.begin(57600);
- for (int i = 0; i < sizeof(handArr); ++i)
- pinMode(handArr[i], OUTPUT);
- Wire.begin();
- RTC.begin();
- attachInterrupt(0, zcDetect, RISING);
- Timer1.initialize(freqStep);
- Timer1.attachInterrupt(dimCheck);
- }
- void zcDetect()
- {
- zcM = true;
- zcH = true;
- for (int i = 0; i < sizeof(handArr); ++i)
- digitalWrite(handArr[i], LOW);
- }
- void dimCheck()
- {
- //MINUTES
- if (zcM)
- {
- if (countM >= minuteBrightness)
- {
- digitalWrite(minutePin, HIGH);
- countM = 0;
- zcM = false;
- }
- else
- countM++;
- }
- //HOURS
- if (zcH)
- {
- if (countH >= hourBrightness)
- {
- digitalWrite(hourPin, HIGH);
- countH = 0;
- zcH = false;
- }
- else
- countH++;
- }
- }
- void setBulbs()
- {
- DateTime now = RTC.now();
- int hour = now.hour();
- int minute = now.minute();
- hourPin = handArr[hour - 1];
- if (minute == 0)
- minutePin = handArr[0];
- else
- minutePin = handArr[(int)ceil(minute/5) - 1];
- dim = analogRead(potPin);
- long tempDim = map(dim, 0, 1023, 1, 1.5);
- minuteBrightness = round(minuteBrightnessArr[(minute % 5) - 1] * tempDim);
- hourBrightness = minuteBrightness - minuteBrightnessArr[4];
- }
- void checkButtonState()
- {
- buttonState = analogRead(buttonPin);
- int stateArr[] = {80, 65, 50, 35, 20};
- }
- void loop()
- {
- setBulbs();
- checkButtonState();
- delay(20);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement