Code Along - Chapter 22

ESP32: 0-4095 to Percent

Use map() to turn a 0-4095 reading into 0 to 100.

Estimated time 5-10 minExercises passed 0 / 1

ESP32 code on the virtual board

The virtual board is an Uno, not an ESP32, so there is no Wi-Fi here. You practise the code around it. A pot reading is a pretend number in a variable, like int reading = 2048;. The LED on GPIO 2 works the same; the test list calls it pin D2.

Exercise 22.1

0-4095 to percent

Not started

An ESP32 reading goes from 0 to 4095. The pot is half way, so reading is 2048. Use map() to turn it into 0 to 100, store it in percent, then print percent.

Sample output
50
void setup() {
  Serial.begin(115200);
  int reading = 2048;     // pretend the pot is half way
  // Make percent with map(), then print it

}

void loop() {
}

Turn on JavaScript to edit, run and test this code in the browser.