จากความจริงข้างต้น เราจึงสามารถนำ ขาที่สามารถอ่านสัญญาณแอนะล็อกได้ (คือใช้เป็น ADC ได้) ของชิพ ESP-WROOM-32 มาเชื่อมต่อกับขาของพอร์ต USB ที่ไม่ได้ใช้งาน ซึ่งในที่นี้ เราใช้ขา SW2 (IO14) มาใช้ โดยการบัดกรีสายไฟ ดังรูป


จากนั้นจึงหาสาย USB ทั่วไป ที่ไม่ใช้แล้ว มาตัดแล้วทำขั้วต่อ โดย สายสีแดงคือไฟ 5 โวลต์ สายสีขาวคือ D+ และสายสีเขียวคือ D- ซึ่งสาย D+ และ D- ต่อกับ ADC2_CH8 และกราวด์ (GND) อยู่ ตามลำดับ และ เตรียมการทดสอบโดยใช้ตัวต้านทานปรับค่าได้ (10 KOhm) ดังรูป

เลือกใช้ Arduino IDE และทำการเพิ่มบอร์ด ESP32 (โดยอาจเลือกบอร์ด Node32S แทนสำหรับบอร์ดคิดไบร์ท) ทำการติดตั้งไลบรารี่ของ HT16K33 16*8 LED Controller และ Adafruit-GFX-library (หากยังไม่ได้ติดตั้งมาก่อน) เพื่อการควบคุมการแสดงผลผ่านจอแอลอีดีอาเรย์บนบอร์ด
รายละเอียดของการเพิ่มบอร์ดอาจอ่านได้จาก https://randomnerdtutorials.com/installing-the-esp32-board-in-arduino-ide-windows-instructions/ และ ข้อมูลเกี่ยวกับ HT16K33 16*8 LED Controller อยู่ใน https://www.adafruit.com/product/1427
เปิดตัวอย่างโค้ด AnalogReadSerial จากนั้นจึงเปลี่ยนขา A0 เป็น 14 และเพิ่มการหน่วงเวลา (delay) เป็น 100 มิลลิวินาที แล้วจึงบันทึกและอัพโหลดโปรแกรม
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(14);
// print out the value you read:
Serial.println(sensorValue);
delay(100); // delay in between reads for stability
}
สังเกตผลบน Serial Monitor จะเห็นว่า ค่าที่แสดง (0-4095) เปลี่ยนตามการหมุนของตัวต้านทานปรับค่าได้
ทดสอบการใช้แอลอีดีอาเรย์ โดยศึกษาจาก ตัวอย่างในไลบรารีที่ดาวน์โหลดมา (เช่น matrix16x8.ino แต่ไม่ขอกล่าวรายละเอียดในที่นี้)
ทำการอัพโหลดโค้ดด้านล่างนี้ ก็จะได้ โวลต์มิเตอร์ที่สร้างจากบอร์ดคิดไบร์ท
#include <Wire.h>
#include <Adafruit_GFX.h>
#include "Adafruit_LEDBackpack.h"
Adafruit_8x16matrix matrix = Adafruit_8x16matrix();
void setup() {
Serial.begin(9600);
Serial.println("DVM on KB");
matrix.begin(0x70); // pass in the address
matrix.setRotation(2); // for KidBright
}
void loop() {
int readVal = analogRead(14); // 12-bit data (0 - 4095)
float voltVal = readVal*3.3/4095.0; // Convert to Volt
// e.g. 3.21: '3' is the first digit and '2' is the first decimal digit
int firstVal = floor(voltVal);
int secondVal = round((voltVal - (float) firstVal)*10.0);
// Serial.print(readVal);
// Serial.print("\t");
Serial.println(voltVal);
matrix.clear(); // clear display
matrix.setTextSize(1);
matrix.setTextWrap(false);
matrix.setTextColor(LED_ON);
matrix.setCursor(2,8); // First Number
matrix.print(firstVal);
matrix.drawPixel(0,6, LED_ON); // decimal point
matrix.setCursor(2,0); // Second Number
matrix.print(secondVal);
matrix.writeDisplay();
delay(500);
}
