#include <Wire.h> // library requires for I2C communication
#include <Adafruit_SSD1306.h>
#include <Encoder.h>
// Encoder myEnc(2, 3);
// int encVal = 0;
// int encOldVal = 0;
const unsigned int MAX_MESSAGE_LENGTH = 25;
char message[MAX_MESSAGE_LENGTH];
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
unsigned long oldOledTime = 0;
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
int progress = 0; // progress of the progressbar
void setup() {
Serial.begin(115200);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
Serial.println("arduino ready");
}
void loop() {
// int encVal = myEnc.read();
// if (encVal != encOldVal) {
// encOldVal = encVal;
// Serial.println(encVal);
// }
//Check to see if anything is available in the serial receive buffer
while (Serial.available() > 0) {
//Create a place to hold the incoming message
static unsigned int message_pos = 0;
//Read the next available byte in the serial receive buffer
char inByte = Serial.read();
//Message coming in (check not terminating character) and guard for over message size
if ( inByte != '\n' && (message_pos < MAX_MESSAGE_LENGTH - 1) )
{
//Add the incoming byte to our message
message[message_pos] = inByte;
message_pos++;
}
//Full message received...
else
{
//Add null character to string
message[message_pos] = '\0';
//Print the message (or do other things)
//Serial.println(message);
//Reset for the next message
message_pos = 0;
}
}
// OLED drawing
if (millis() - oldOledTime > 10) {
oldOledTime = millis();
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(5, 7);
display.print(message);
display.drawRect(5, 18, 116, 39, 1);
display.fillRect(8, 21, progress, 33, 1);
display.display();
// increase the progress value to go over 0-100
progress = progress + 1;
if (progress > 110) {
progress = 0;
}
}
}