#include <U8g2lib.h>
#include <math.h>
// Define the OLED display object
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
void setup() {
// Initialize the OLED display
u8g2.begin();
// Set up the sine wave parameters
float frequency = 1.0; // Frequency of the sine wave in Hz
float amplitude = 30.0; // Amplitude of the sine wave
float phase = 0.0; // Phase offset of the sine wave
// Loop to animate the sine wave
while (true) {
// Clear the display
u8g2.clearBuffer();
// Plot the sine wave with more points for smoother animation
for (int x = 0; x < u8g2.getWidth(); x += 2) {
//float y = amplitude * sin(2 * PI * frequency * x / u8g2.getWidth() + phase) + u8g2.getHeight() / 2;
float y = analogRead(0)+ u8g2.getHeight() / 2;
u8g2.drawPixel(x, y);
}
// Send the buffer to the OLED display
u8g2.sendBuffer();
// Reduce delay for smoother animation
//delay(1);
// Shift the phase to create a scrolling effect
phase += 0.1;
}
}
void loop() {
// Empty loop since animation is handled in setup()
}