Created
January 9, 2020 17:44
-
-
Save joeycastillo/c7b246add2b406aa96b1a2e0ec3f0553 to your computer and use it in GitHub Desktop.
This file contains 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 "Adafruit_Arcada.h" | |
Adafruit_Arcada arcada; | |
const int16_t pixelWidth = ARCADA_TFT_WIDTH; | |
const int16_t pixelHeight = ARCADA_TFT_HEIGHT; | |
void setup(void) { | |
Serial.begin(115200); | |
// Start TFT | |
if (!arcada.arcadaBegin()) { | |
Serial.print("Failed to begin"); | |
while (1); | |
} | |
arcada.displayBegin(); | |
// Turn on backlight | |
arcada.setBacklight(255); | |
if (!arcada.createFrameBuffer(ARCADA_TFT_WIDTH, ARCADA_TFT_HEIGHT)) { | |
Serial.print("Failed to allocate framebuffer"); | |
while (1); | |
} | |
if (!setupDataAcquuisition()) { | |
Serial.print("Failed to set up data acquisition"); | |
while (1); | |
} | |
} | |
void loop() { | |
uint8_t data = 0; | |
if (acquireData(&data)) { | |
uint16_t *framebuffer= arcada.getFrameBuffer(); | |
// shift everything one pixel to the left | |
for(int x = 0; x < pixelWidth - 1; x++) { | |
for(int y = 0; y < pixelHeight; y++) { | |
framebuffer[y * pixelWidth + x] = framebuffer[y * pixelWidth + x + 1]; | |
} | |
} | |
// fill in the last column | |
for(int y = 0; y < pixelHeight; y++) { | |
framebuffer[y * pixelWidth + pixelWidth - 1] = ARCADA_BLACK; | |
} | |
framebuffer[(pixelHeight - (pixelHeight - 1) * data / 255 - 1) * pixelWidth + pixelWidth - 1] = ARCADA_WHITE; | |
arcada.blitFrameBuffer(0, 0, true, false); | |
} | |
} | |
// you can acquire data from anywhere, this sketch just pulls some debug data from Serial1 (the RX pin) | |
// set up sensors or whatever and return true if working. | |
bool setupDataAcquuisition() { | |
Serial1.begin(115200); | |
return true; | |
} | |
// return true if you acquired new data, false if you have nothing new to plot. | |
// in this case we only want to plot a new data point when it's at the correct offset in our buffer. | |
// return one unsigned byte of data by reference (*data = newValue) | |
bool acquireData(uint8_t *data) { | |
static int count = 0; | |
static int buf[5]; | |
if (Serial1.available()) { | |
int val = Serial1.read(); | |
buf[0] = buf[1]; | |
buf[1] = buf[2]; | |
buf[2] = buf[3]; | |
buf[3] = buf[4]; | |
buf[4] = val; | |
count++; | |
if (val == 0xAA && count > 61) { // 0xAA is the end of record indicator in my case | |
count = 0; | |
*data = buf[0]; | |
return true; | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment