#include <Wire.h>
#include <LiquidCrystal.h>
#include "RTClib.h"
#include "pitches.h"
#define LDR_PIN A0
#define SPEAKER_PIN 6
// These constants should match the photoresistor's "gamma" and "rl10" attributes
const float GAMMA = 0.7;
const float RL10 = 50;
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Sun", "Mon", "Tues", "Wed", "Thur", "Fri", "Sat"};
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
void setup()
{
Serial.begin(115200);
//kill function
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
//pin mdoes
pinMode(LDR_PIN, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(SPEAKER_PIN, OUTPUT);
Wire.begin();
// Initializes the LCD
lcd.begin(1, 1);
int analogValue = analogRead(A0);
float voltage = analogValue / 1024. * 5;
float resistance = 2000 * voltage / (1 - voltage / 5);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
lcd.print(lux);
}
void loop()
{
int analogValue = analogRead(A0);
float voltage = analogValue / 1024. * 5;
float resistance = 2000 * voltage / (1 - voltage / 5);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
DateTime now = rtc.now();
lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);
lcd.print(" ");
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.print(':');
lcd.print(now.second(), DEC);
delay(1000);
lcd.clear();
delay(0.000000000000000000001);
if (lux >= 400) {
digitalWrite(LED_BUILTIN, HIGH);
tone(SPEAKER_PIN, NOTE_G4);
delay(250);
tone(SPEAKER_PIN, NOTE_C5);
delay(250);
tone(SPEAKER_PIN, NOTE_G4);
delay(250);
tone(SPEAKER_PIN, NOTE_C5);
delay(250);
tone(SPEAKER_PIN, NOTE_C4);
delay(1000);
noTone(SPEAKER_PIN);
digitalWrite(LED_BUILTIN, LOW);
} else {
return;
}
}
pico:GP0
pico:GP1
pico:GND.1
pico:GP2
pico:GP3
pico:GP4
pico:GP5
pico:GND.2
pico:GP6
pico:GP7
pico:GP8
pico:GP9
pico:GND.3
pico:GP10
pico:GP11
pico:GP12
pico:GP13
pico:GND.4
pico:GP14
pico:GP15
pico:GP16
pico:GP17
pico:GND.5
pico:GP18
pico:GP19
pico:GP20
pico:GP21
pico:GND.6
pico:GP22
pico:RUN
pico:GP26
pico:GP27
pico:GND.7
pico:GP28
pico:ADC_VREF
pico:3V3
pico:3V3_EN
pico:GND.8
pico:VSYS
pico:VBUS
wokwi-buzzer-0:1
wokwi-buzzer-0:2
wokwi-ds1307-0:GND
wokwi-ds1307-0:5V
wokwi-ds1307-0:SDA
wokwi-ds1307-0:SCL
wokwi-ds1307-0:SQW
wokwi-photoresistor-sensor-0:VCC
wokwi-photoresistor-sensor-0:GND
wokwi-photoresistor-sensor-0:DO
wokwi-photoresistor-sensor-0:AO
wokwi-lcd1602-0:VSS
wokwi-lcd1602-0:VDD
wokwi-lcd1602-0:V0
wokwi-lcd1602-0:RS
wokwi-lcd1602-0:RW
wokwi-lcd1602-0:E
wokwi-lcd1602-0:D0
wokwi-lcd1602-0:D1
wokwi-lcd1602-0:D2
wokwi-lcd1602-0:D3
wokwi-lcd1602-0:D4
wokwi-lcd1602-0:D5
wokwi-lcd1602-0:D6
wokwi-lcd1602-0:D7
wokwi-lcd1602-0:A
wokwi-lcd1602-0:K
r1:1
r1:2