Project 5, photoresistor nightlight

This commit is contained in:
2026-06-04 13:22:25 -04:00
parent 9321b39891
commit 1c294cfb94
6 changed files with 122 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
#define PIN_PHOTORESISTOR 1
#define PIN_LED 14
#define ADC_MAX (1 << 12)
#define ADC_VOLTAGE 3300
void setup()
{
Serial.begin(115200);
ledcAttach(PIN_LED, 1000, 12);
}
void loop()
{
int adcvalue = analogRead(PIN_PHOTORESISTOR);
int adcvoltage = (ADC_MAX / ADC_VOLTAGE) * adcvalue;
Serial.printf("ADC Value: %d Voltage (int): %d\n", adcvalue, adcvoltage);
ledcWrite(PIN_LED, adcvoltage);
}