Code Along - Chapter 21

ESP32: LOW, MID or HIGH

Sort 0-4095 readings into LOW, MID and HIGH with if and else.

Estimated time 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 21.1

LOW, MID or HIGH

Not started

The loop gives you three pretend readings, one at a time. For each one print:

  • LOW if it is below 1365
  • MID if it is below 2730
  • HIGH otherwise
Sample output
LOW
MID
HIGH
int readings[] = {500, 2000, 3500};  // three pretend pot readings

void setup() {
  Serial.begin(115200);
  for (int i = 0; i < 3; i++) {
    int reading = readings[i];
    // Print LOW, MID or HIGH

  }
}

void loop() {
}

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