Project 5, photoresistor nightlight
This commit is contained in:
19
05-photoresistors/05-photoresistors.ino
Normal file
19
05-photoresistors/05-photoresistors.ino
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user