#define ledPin 4
#define sensorPin 2
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
pinMode(ledPin, OUTPUT); //輸出LED
pinMode(sensorPin, INPUT); //輸入可變電阻器
}
void loop() {
sensorValue = analogRead(sensorPin);
Serial.println(sensorValue);
// turn the ledPin on
digitalWrite(ledPin, HIGH);
// stop the program for <sensorValue> milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for for <sensorValue> milliseconds:
delay(sensorValue);
}