// ESP32 WiFi SCAN, PULLUP, PULLDOWN, RGBLED
// https://wokwi.com/projects/305569599398609473
// board type: "ESP32C3 Dev Module", "Nologo ESP32C3 Super Mini"
// Enable Serial Comms: IDE >> Tools >> USB CDC On Boot
// https://www.espboards.dev/esp32/esp32-c3-zero/
// https://www.espboards.dev/img/7xS3z0FLsA-977.png
// https://www.waveshare.com/wiki/ESP32-C3-Zero
// https://docs.wokwi.com/guides/esp32
#include <WiFi.h>
#define RGB_BUILTIN 8 // ESP32C3mini = 8, ESP32C3zero = 10
#define RGB RGB_BUILTIN
bool flag_rgbledtest = 1;
byte color_stage = 0, color_stages = 6; // color stages for zero.h
int count = 0, minimum = 0, maximum = 255, increas, decreas; // counters - misspelled to format words
int iopin[] = {0, 1, 2, 3, 4, 5, 6, 7, /* 8, RGB */ 9, 10, 18, 19/*, 20, 21*/};
int iosize = sizeof(iopin) / sizeof(iopin[0]);
unsigned long timer, timeout = 3000, fadeTimer, fadeTimeout = 2000;
void setup() {
Serial.begin(115200);
Serial.print("\nInitialize WiFi... ");
WiFi.mode(WIFI_STA);
Serial.println("done.");
}
void loop() {
rgbledtest();
rgbLedWrite(RGB, 0, 255, 0); // green
inputpullupdowntest();
// gpiotest();
// interrupttest();
wifiscan();
timeout = 5000;
flag_rgbledtest = 1;
timer = millis();
}
void rgbledtest() {
if (flag_rgbledtest) {
flag_rgbledtest = 0;
Serial.println("WS2812 RGB LED Test");
}
while (millis() - timer < timeout) {
if (micros() - fadeTimer > fadeTimeout) {
fadeTimer = micros();
if (increas++ == maximum) { // increment color until counter is max
increas = minimum; // reset color counter
if (color_stage++ == color_stages) // increment stage until stage is max
color_stage = 1; // reset stage
}
decreas = maximum - increas; // invert counter to decrease values
switch (color_stage) { // blend colors one bit per step
case 0: rgbLedWrite(RGB, increas, minimum, minimum); break; // blk (0,0,0) to red (1,0,0) - blk one time only
case 1: rgbLedWrite(RGB, maximum, increas, minimum); break; // red (1,0,0) to yel (1,1,0)
case 2: rgbLedWrite(RGB, decreas, maximum, minimum); break; // yel (1,1,0) to grn (0,1,0)
case 3: rgbLedWrite(RGB, minimum, maximum, increas); break; // grn (0,1,0) to cyn (0,1,1)
case 4: rgbLedWrite(RGB, minimum, decreas, maximum); break; // cyn (0,1,1) to blu (0,0,1)
case 5: rgbLedWrite(RGB, increas, minimum, maximum); break; // blu (0,0,1) to mag (1,0,1)
case 6: rgbLedWrite(RGB, maximum, minimum, decreas); break; // mag (1,0,1) to red (1,0,0)
default: break;
}
}
}
}
void inputpullupdowntest() {
int dly = 1000;
Serial.print("INPUT test ");
for (int i = 0; i < iosize; i++) {
pinMode(iopin[i], INPUT);
delay(1); // allow pin to settle
Serial.print(digitalRead(iopin[i])); // floating
}
Serial.println();
delay(dly);
Serial.print("INPUT_PULLUP test ");
for (int i = 0; i < iosize; i++) {
pinMode(iopin[i], INPUT_PULLUP);
delay(1); // allow pin to settle
Serial.print(digitalRead(iopin[i])); // all should be "1"
}
Serial.println();
delay(dly);
Serial.print("INPUT_PULLDOWN test ");
for (byte i = 0; i < iosize; i++) {
pinMode(iopin[i], INPUT_PULLDOWN);
delay(1); // allow pin to settle
Serial.print(digitalRead(iopin[i])); // all should be "0"
}
Serial.println();
delay(dly);
Serial.print("OUTPUT HIGH test ");
for (byte i = 0; i < iosize; i++) {
pinMode(iopin[i], OUTPUT);
delay(1); // allow pin to settle
digitalWrite(iopin[i], HIGH);
delay(1); // allow pin to settle
Serial.print(digitalRead(iopin[i]));
}
Serial.println();
delay(dly);
Serial.print("OUTPUT LOW test ");
for (byte i = 0; i < iosize; i++) {
pinMode(iopin[i], OUTPUT);
delay(1); // allow pin to settle
digitalWrite(iopin[i], LOW);
delay(1); // allow pin to settle
Serial.print(digitalRead(iopin[i]));
}
Serial.println();
delay(dly);
}
void wifiscan() {
Serial.print("Scanning WiFi... ");
int networks = WiFi.scanNetworks(); // number of networks
Serial.print("Networks found: ");
if (networks == 0) {
Serial.println("No networks found.");
} else {
Serial.println(networks);
for (int i = 0; i < networks; ++i) {
Serial.print(i + 1);
Serial.print(": ");
Serial.print(WiFi.SSID(i));
Serial.print(" (");
Serial.print(WiFi.RSSI(i));
Serial.print(")");
Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN) ? " " : "*");
delay(10);
}
}
Serial.println();
}