// ILI9488 Wokwi Custom Chip — Oscilloscope Demo
// Uses the TFT_eSPI library configured for ILI9488
// Requires: oscilloscope.h (same directory)
#define WOKWI_SIMULATION
#include <TFT_eSPI.h>
#include <SPI.h>
#include "oscilloscope.h"
// ─── Pin definitions — must match build_opt.h ────────────────────────────────
#define PIN_SCLK 18
#define PIN_MOSI 23
#define PIN_MISO -1 // not used
#define PIN_CS 15
#define PIN_DC 17
#define PIN_RST 4
// ─── Hardware objects ────────────────────────────────────────────────────────
TFT_eSPI tft = TFT_eSPI();
// Oscilloscope renderer: −1 … +1 V range, portrait 320×480
Oscilloscope osc(tft,
/*vMin=*/ -1.2f,
/*vMax=*/ 1.2f,
/*ch=*/ "CH1",
/*time=*/ "10 ms/div");
// Test signal source: fundamental + harmonics → approximates a square wave
SineHarmonicSource src;
// ─── Setup ───────────────────────────────────────────────────────────────────
void setup() {
Serial.begin(115200);
Serial.println("ILI9488 Oscilloscope demo starting…");
SPI.begin(PIN_SCLK, PIN_MISO, PIN_MOSI, PIN_CS);
// Hardware reset sequence
pinMode(PIN_RST, OUTPUT);
digitalWrite(PIN_RST, LOW); delay(100);
digitalWrite(PIN_RST, HIGH); delay(100);
pinMode(PIN_DC, OUTPUT);
digitalWrite(PIN_DC, LOW); delay(100);
digitalWrite(PIN_DC, HIGH); delay(100);
digitalWrite(PIN_DC, LOW);
tft.init();
tft.setRotation(1); // Portrait 320 × 480
// ── Build the test signal ──────────────────────────────────────────────
// Odd-harmonic square-wave approximation (5 terms):
// y(t) = sin(2π·50t) fundamental 50 Hz A=1.00
// + (1/3)·sin(2π·150t) 3rd harmonic 150 Hz A=0.33
// + (1/5)·sin(2π·250t) 5th harmonic 250 Hz A=0.20
// + (1/7)·sin(2π·350t) 7th harmonic 350 Hz A=0.14
// + (1/9)·sin(2π·450t) 9th harmonic 450 Hz A=0.11
// Adjust frequencies / amplitudes freely — see oscilloscope.h for the API.
src.setSquareApproximation(/*fundamental=*/50.0f,
/*peakAmplitude=*/1.0f,
/*harmonics=*/5);
// Optional: manually set trigger level
osc.setTriggerLevel(0.5f, /*show=*/true);
// Initialise the oscilloscope screen
osc.begin();
Serial.println("Ready.");
}
// ─── Loop
void loop() {
// OSC_DEMO_LOOP handles timing, sample generation and screen update.
// Replace with real ADC reads for actual measurements:
// float v = analogRead(34) / 4095.0f * 3.3f - 1.65f; // centre at 0
// osc.pushSample(v);
OSC_DEMO_LOOP(osc, src);
}