/*
ESP32 DAC Oscilloscope Art Demo
espdac-scope-art.ino
Generates pattern on oscilloscope
Scope must be in X-Y mode
Original scope code by Bitluni - https://github.com/bitluni/OsciDisplay/
DroneBot Workshop 2022
https://dronebotworkshop.com
*/
// Include DAC and Math Libraries
#include <driver/dac.h>
#include <math.h>
// Define variable for increment
float t = 0;
void setup() {
// Enable both DAC channels
dac_output_enable(DAC_CHANNEL_1);
dac_output_enable(DAC_CHANNEL_2);
}
void loop() {
// Move two channels through sine and cosine waves
// Increment variable
t += 0.01;
// Step through circle
for (float f = 0; f < M_PI * 2; f += 0.01) {
dac_output_voltage(DAC_CHANNEL_1, sin(f) * 120 + 120);
dac_output_voltage(DAC_CHANNEL_2, cos(f + t) * 120 + 120);
}
// Send DAC output HIGH to provide scope trigger on both channels
dac_output_voltage(DAC_CHANNEL_1, 255);
dac_output_voltage(DAC_CHANNEL_2, 255);
// Short delay
delay(10);
}