Created
October 7, 2023 12:04
-
-
Save hollyhockberry/594d65b27d1feb3ea3575850d4ba973f to your computer and use it in GitHub Desktop.
GLASS2 with M5ATOM-S3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <M5UnitGLASS2.h> | |
M5UnitGLASS2 display (2, 1, 400000); | |
constexpr size_t POINTS = 128; | |
int points[POINTS]; | |
void setup() { | |
display.init(); | |
display.startWrite(); | |
display.fillScreen(TFT_BLACK); | |
if (display.width() < display.height()) { | |
display.setRotation(display.getRotation() ^ 1); | |
} | |
for (auto x = 0; x < POINTS; ++x) { | |
points[x] = -1; | |
} | |
display.display(); | |
} | |
void loop() { | |
static int amplitude = 0; | |
static int delta = 1; | |
amplitude += delta; | |
if (amplitude >= 32) { | |
delta = -1; | |
} else if (amplitude <= 0) { | |
delta = 1; | |
} | |
display.waitDisplay(); | |
for (int x = 0; x < POINTS; ++x) { | |
const float freq = 5.f * sin(2 * PI * millis() / 10000.0); | |
const float fy = amplitude * sin(2 * PI * freq * x / 128); | |
const int y = map(fy, -32, 32, 0, 64 - 1); | |
if (points[x] == y) { | |
continue; | |
} | |
display.drawPixel(x, points[x], BLACK); | |
display.drawPixel(x, y, WHITE); | |
points[x] = y; | |
} | |
display.display(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment