#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// Declaration for GPO sending buttons and pins
const int buttonPins[] = {10, 11, 12};
const int gpiOutputs[] = {6, 7, 8};
// Declaration for the GPI listening pins and associated variables
const int gpiInputs[] = {A0, A1, A2, A3}; // Array of analog input pins for GPIs
// Other variables
int cpt = 1;
bool Ready = false;
bool showLogoAtStartup = true;
float gpiVoltage[4];
// 'Adrienne GPI Tester Logo', 128x64px
const unsigned char AdrienneGPITesterLogo [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x08, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x80, 0x0c, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x03, 0xc0, 0x0c, 0x02, 0x00, 0x08, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x03, 0x80, 0x14, 0x3e, 0x4e, 0x1c, 0x20, 0x10, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x86, 0x00, 0x36, 0x26, 0x5a, 0x3d, 0x31, 0x30, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0xfc, 0x00, 0x26, 0x26, 0x72, 0x39, 0x71, 0x31, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0xfc, 0x00, 0x7f, 0xe6, 0x62, 0x39, 0x51, 0x51, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x86, 0x00, 0x7e, 0x4e, 0x62, 0x21, 0xd1, 0x51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x03, 0x80, 0xc2, 0x4a, 0x46, 0xa1, 0x97, 0xd3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x03, 0xc0, 0x83, 0x5a, 0x47, 0xe5, 0x9d, 0x9d, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x81, 0x01, 0x72, 0x43, 0x2d, 0x09, 0x0d, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x01, 0xa0, 0x40, 0x38, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x40, 0x00, 0x00, 0x80, 0x00, 0x00,
0x00, 0x7f, 0xff, 0xff, 0xf3, 0xff, 0xff, 0xfe, 0x3f, 0x80, 0xc0, 0x00, 0x01, 0x80, 0x00, 0x00,
0x00, 0x7f, 0xff, 0xff, 0xe3, 0xff, 0xff, 0xfe, 0x3f, 0x80, 0xc0, 0x00, 0x03, 0x80, 0x00, 0x00,
0x00, 0x7f, 0xff, 0xff, 0xc3, 0xff, 0xff, 0xfe, 0x3f, 0x81, 0xc0, 0x00, 0x03, 0x00, 0x00, 0x00,
0x00, 0x7f, 0xff, 0xff, 0xc3, 0xff, 0xff, 0xfe, 0x3f, 0x81, 0xc0, 0x01, 0xc3, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x80, 0x00, 0x03, 0xf8, 0x00, 0xfe, 0x3f, 0x83, 0xf0, 0xc3, 0x87, 0xe1, 0x02, 0x00,
0x00, 0x7f, 0x00, 0x00, 0x03, 0xf8, 0x00, 0xfe, 0x3f, 0x8f, 0xf9, 0xe7, 0x1f, 0xe7, 0x86, 0x60,
0x00, 0x7f, 0x00, 0x00, 0x03, 0xf8, 0x00, 0xfe, 0x3f, 0x8f, 0xe3, 0xe6, 0x1f, 0xc7, 0x8f, 0xc0,
0x00, 0x7f, 0x00, 0x00, 0x03, 0xf8, 0x00, 0xfe, 0x3f, 0x81, 0x83, 0x67, 0x06, 0x0d, 0x9f, 0x00,
0x00, 0x7f, 0x00, 0x00, 0x03, 0xf8, 0x00, 0xfe, 0x3f, 0x81, 0x82, 0x67, 0x06, 0x0d, 0x87, 0x00,
0x00, 0x7f, 0x00, 0x00, 0x03, 0xf8, 0x00, 0xfe, 0x3f, 0x83, 0x07, 0xc3, 0x86, 0x0f, 0x86, 0x00,
0x00, 0x7f, 0x00, 0x00, 0x03, 0xf8, 0x00, 0xfe, 0x3f, 0x83, 0x07, 0x83, 0x86, 0x1f, 0x06, 0x00,
0x00, 0x7f, 0x00, 0x00, 0x03, 0xf8, 0x00, 0xfe, 0x3f, 0x83, 0x07, 0x01, 0xc4, 0x1c, 0x0e, 0x00,
0x00, 0x7f, 0x00, 0x00, 0x03, 0xf8, 0x00, 0xfe, 0x3f, 0x83, 0x0e, 0x01, 0xce, 0x18, 0x06, 0x00,
0x00, 0x7f, 0x00, 0x00, 0x03, 0xf8, 0x00, 0xfe, 0x3f, 0x87, 0x1e, 0x11, 0x8c, 0x78, 0x6c, 0x00,
0x00, 0x7f, 0x00, 0x0f, 0xe3, 0xf8, 0x00, 0xfe, 0x3f, 0x87, 0x3e, 0x71, 0x8c, 0xdd, 0xcc, 0x00,
0x00, 0x7f, 0x00, 0x0f, 0xe3, 0xff, 0xff, 0xfe, 0x3f, 0x87, 0xef, 0xe3, 0x0f, 0x9f, 0x8c, 0x00,
0x00, 0x7f, 0x00, 0x0f, 0xe3, 0xff, 0xff, 0xfe, 0x3f, 0x87, 0xcf, 0x86, 0x0f, 0x1e, 0x08, 0x00,
0x00, 0x7f, 0x00, 0x0f, 0xe3, 0xff, 0xff, 0xfe, 0x3f, 0x83, 0x84, 0x0c, 0x0e, 0x18, 0x00, 0x00,
0x00, 0x7f, 0x00, 0x0f, 0xe3, 0xff, 0xff, 0xfe, 0x3f, 0x82, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x00, 0x0f, 0xe3, 0xff, 0xff, 0xfe, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x00, 0x0f, 0xe3, 0xf8, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x00, 0x0f, 0xe3, 0xf8, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x00, 0x0f, 0xe3, 0xf8, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x00, 0x0f, 0xe3, 0xf8, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x00, 0x0f, 0xe3, 0xf8, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x00, 0x0f, 0xe3, 0xf8, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0xff, 0xff, 0xe3, 0xf8, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0xff, 0xff, 0xe3, 0xf8, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0xff, 0xff, 0xe3, 0xf8, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0xff, 0xff, 0xe3, 0xf8, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0xff, 0xff, 0xe3, 0xf8, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x60, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x40, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xf3, 0x63, 0xd1, 0x6e, 0xd8,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0xcf, 0x72, 0xd1, 0xeb, 0xdc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0xbd, 0x52, 0xf1, 0xeb, 0x14,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0xfd, 0x72, 0xf1, 0xab, 0x1c,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0xcf, 0x42, 0xb1, 0xab, 0xd0,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0xfb, 0x73, 0xa0, 0xaa, 0xdc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 1040)
const int epd_bitmap_allArray_LEN = 1;
const unsigned char* epd_bitmap_allArray[1] = {
AdrienneGPITesterLogo
};
void setup() {
Serial.begin(115200);
// Set buttons as input and GPO pins as output and set the three GPO outputs to HIGH
for (int i = 0; i < 3; i++) {
pinMode(buttonPins[i], INPUT_PULLUP);
pinMode(gpiOutputs[i], OUTPUT);
digitalWrite(gpiOutputs[i], HIGH);
}
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
delay(200);
display.clearDisplay();
if (showLogoAtStartup == true) {
// display the logo for 3 seconds
display.drawBitmap(0, 0, AdrienneGPITesterLogo, 128, 64, WHITE);
display.display();
delay(3000);
}
// Set display properties
display.setTextSize(1);
display.setTextColor(WHITE);
}
void loop() {
display.clearDisplay();
showTitle();
readInputsVoltage();
//display.setCursor(6, 15);
//display.println(gpiVoltage[1]);
if (Ready == true) {
display.setCursor(6, 17);
display.println("tadaaaa");
}
else {
if (gpiVoltage[0] < 3) {
display.setCursor(6, 17);
display.println("GPI not connected!");
display.setCursor(0, 30);
display.println("Check cable and board");
display.setCursor(0, 40);
display.println("initialization");
display.setCursor(5, 53);
display.println(gpiVoltage[1]);
}
else {
Ready = true;
}
}
display.display();
// listenForGPI(cpt);
// checkButtons();
// display.display();
// if (cpt < 4) {
// cpt = cpt +1;
// }
// else {
// cpt = 1;
// }
delay(200);
}
void checkButtons() {
for (int i = 0; i < 3; i++) {
byte buttonState = digitalRead(buttonPins[i]);
if (buttonState == LOW) {
updateDisplay(i+1);
}
else {
}
}
}
void showTitle() {
display.setCursor(10, 2);
display.println("Adrienne GPI Tester");
// temporary, only needed for the simulator... to delete for the actual Arduino
display.drawLine (0, 15, 127, 15, WHITE);
}
void listenForGPI(int cpt) {
display.setCursor(6, 22);
switch (cpt) {
case 1:
display.println("Listening for GPI");
break;
case 2:
display.println("Listening for GPI.");
break;
case 3:
display.println("Listening for GPI..");
break;
case 4:
display.println("Listening for GPI...");
break;
}
}
void sendGPO(){
}
void updateDisplay(int buttonNumber) {
if (buttonNumber > 0) {
writeToDisplay(0,10,"You pressed " + String(buttonNumber));
}
}
void writeToDisplay(int x, int y, String message) {
display.clearDisplay();
display.setCursor(x, y);
display.println(message);
display.display();
}
void readInputsVoltage() {
for (int i = 0; i < 4; i++) {
float sensorValue = analogRead(gpiInputs[i]);
gpiVoltage[i] = sensorValue * (5.0 / 1023.0);
Serial.println("A" + String(i) + " = " + String(gpiVoltage[i]) + "V");
}
//float sensorValue1 = analogRead(A0);
//gpiVoltage1 = sensorValue1 * (5.0 / 1023.0);
//Serial.println(gpiVoltage1);
//float sensorValue2 = analogRead(A1);
//gpiVoltage2 = sensorValue2 * (5.0 / 1023.0);
//float sensorValue3 = analogRead(A2);
//gpiVoltage3 = sensorValue3 * (5.0 / 1023.0);
//float sensorValue4 = analogRead(A3);
//gpiVoltage4 = sensorValue4 * (5.0 / 1023.0);
}