ESP32-Bac-Semis/esp32_blink.ino
2023-01-05 22:05:51 +01:00

40 lines
714 B
C++

#define LED 13
#include "OneWire.h"
#include "DallasTemperature.h"
OneWire oneWire(A3);
DallasTemperature ds(&oneWire);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(LED, OUTPUT);
ds.begin();
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(LED, HIGH);
for(int i=0; i < 100; ++i) {
delay(50);
print_light();
}
digitalWrite(LED, LOW);
for(int i=0; i < 100; ++i) {
delay(50);
print_light();
}
}
void print_light() {
int val = analogRead(A0);
Serial.print("Light: ");
Serial.print(val);
ds.requestTemperatures();
int t = ds.getTempCByIndex(0);
Serial.print("; Temp: ");
Serial.println(t);
}