Created
February 15, 2018 14:56
-
-
Save MelvinStans/a1ec1d85404b5a23f7bb5915cb85d11c to your computer and use it in GitHub Desktop.
Display analog input in a time/value graph on a OLED screen.
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 <SPI.h> | |
#include "SSD1306Spi.h" | |
// The OLED display width and height | |
#define int DISPLAY_HEIGHT = 64; | |
#define int DISPLAY_WIDTH = 128; | |
SSD1306Spi display(0,16,2); // RESET, DC, CS | |
byte count; | |
byte sensorArray[128]; | |
byte drawHeight; | |
void setup() { | |
// Init and flip the OLED display | |
display.init(); | |
display.flipScreenVertically(); | |
// Set contrast and font | |
display.setContrast(255); | |
display.setFont(ArialMT_Plain_10); | |
// Display some info on the OLED | |
display.clear(); | |
for (count = 0; count <= DISPLAY_WIDTH; count++) //zero all elements | |
{ | |
sensorArray[count] = 0; | |
} | |
} | |
// handle websocket requests forever. | |
void loop() { | |
drawHeight = map(analogRead(17), 0, 1023, 0, DISPLAY_HEIGHT ); | |
sensorArray[0] = drawHeight; | |
for (count = 1; count <= DISPLAY_WIDTH; count++ ){ | |
display.drawLine(count, DISPLAY_HEIGHT, count, DISPLAY_HEIGHT - sensorArray[count - 1]); | |
} | |
drawAxises(); | |
display.display(); //needed before anything is displayed | |
display.clear(); //clear before new drawing | |
for (count = DISPLAY_WIDTH; count >= 2; count--) // count down from 160 to 2 | |
{ | |
sensorArray[count - 1] = sensorArray[count - 2]; | |
} | |
} | |
void drawAxises(){ | |
display.drawLine(0,0,0,DISPLAY_HEIGHT); | |
display.drawLine(DISPLAY_WIDTH-1,0,DISPLAY_WIDTH-1,DISPLAY_HEIGHT); | |
for (count = 0; count < 64; count += 10) | |
{ | |
display.drawLine(DISPLAY_WIDTH, count, DISPLAY_WIDTH-5, count); | |
display.drawLine(0, count, 5, count); | |
} | |
for (count = 10; count < DISPLAY_WIDTH; count += 10) | |
{ | |
display.setPixel(count, 0); | |
display.setPixel(count, DISPLAY_HEIGHT); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment