diff --git a/LaserClock/LaserClock.ino b/LaserClock/LaserClock.ino index 991d688..c29d6b8 100644 --- a/LaserClock/LaserClock.ino +++ b/LaserClock/LaserClock.ino @@ -3,7 +3,7 @@ * * Program for a binary laser clock * - * Setup: a Button on pin 12, Led pin 13, Laser / LED on pin 2-11 needs to be pwm! RTC-Modul DS3231 required + * Setup: a Button on pin 12, Led pin 13, Laser / LED on pin 2-11 needs to be pwm! RTC-Modul DS3231 required, AmbientLightSensor on pin A0 * */ #include @@ -12,6 +12,9 @@ DS3231 clock; #define pressed digitalRead(12) == LOW +#define lightoff 1010 +#define lighton 970 +const unsigned char lightSensPin; //pins for hour display const unsigned char H[] = {8,9,10,11}; @@ -19,15 +22,26 @@ const unsigned char H[] = {8,9,10,11}; const unsigned char M[] = {2,3,4,5,6,7}; //intensity of laser, when "off": 0 -> 0% on; 255 -> 100% on -const unsigned int offtime = 160; +const unsigned int offtime = 170; + +//lowbrightnes values +const unsigned char offtime_lb = 140; +const unsigned char ontime_lb = 185; + +bool brightmode = true; bool houtremp; void set(const unsigned char pin, bool on) { - if(on) - digitalWrite(pin, HIGH); - else - analogWrite(pin, offtime); + if(on) { + if(brightmode) { + digitalWrite(pin, HIGH); + } else { + analogWrite(pin, ontime_lb); + } + } else { + analogWrite(pin, brightmode ? offtime : offtime_lb); + } } //prints the data to the lasers, write(0,0)-> all off, write()-> all on @@ -119,4 +133,10 @@ void loop() { digitalWrite(13, millis()/1000 % 2 == 0); delay(500); + int brightness = analogRead(A0); + if(brightness < lighton) { + brightmode = true; + } else if(brightness > lightoff) { + brightmode = false; + } }