// simple project using Arduino UNO and 128x64 OLED Display to display audio analyzer
// in the real project, Audio Analyzer Module from DFRobot is used
// for this WOKWI version, the bars are moving randomly
// modification of a project created by upir, 2023
// youtube channel: https://www.youtube.com/upir_upir
// YOUTUBE VIDEO: https://youtu.be/dCofwhHcW7Y
#include <SPI.h> // Arduino SPI library
#include <Adafruit_GFX.h> // Core graphics library
// #include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <Adafruit_ILI9341.h> // Lets use the wokwi stuff for now
byte audio_bar_height[7]; // sizes for the individual bars
byte audio_bar_peak[7]; // positions for the individual peaks (lines over the bars)
#define TFT_DC 9
#define TFT_CS 10
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
void setup() {
tft.begin();
tft.setRotation(3);
tft.setCursor(26, 120);
tft.setTextColor(ILI9341_RED);
tft.setTextSize(3);
tft.println("Hello, TFT!");
tft.setCursor(20, 160);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(2);
tft.println("I can has colors?");
// Meme reference: https://english.stackexchange.com/questions/20356/origin-of-i-can-haz
}
void loop() { // main loop
// clear buffer for storing display content in RAM
// for (int i=0; i<7; i++) { // loop for every fraquency (63Hz, 160Hz, 400Hz, 1kHz, 2.5kHz, 6.25kHz and 16kHz)
// int random_value = random(1024); // calculate random value between 0-1024
// audio_bar_height[i] = audio_bar_height[i] + ((map(random_value, 0, 1024, 0, 53) - audio_bar_height[i]) / 4.0); // update the bar with a new value (slowly)
// calculate the peak position
// if (audio_bar_peak[i] < audio_bar_height[i]) { // if the peak is below the current bar size
// audio_bar_peak[i] = audio_bar_height[i]; // move peak to the new max. position (i.e. size of the bar)
// } else if (audio_bar_peak[i] > audio_bar_height[i]) { // if the bar is lower than the peak
// audio_bar_peak[i]--; // slowly move the peak down, one pixel every frame
// }
// draw bar
// draw peak
//}
// send buffer from RAM to display controller
}