#include "U8glib.h"
#include "USBHIDKeyboard.h"
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0);
int xmax=128;
int ymax=62;
int xcenter=xmax/2;
int ycenter=ymax/2+10;
int arc=ymax/2;
int angle=0;
char* label[] = {"LOAD","COOLANT","INTAKE", "VOLT"};
int labelXpos[] = {53, 45, 49, 53};
#define potmeterPin A1
int p, w, c, m, a=10;
int curpot=0, curaud=0;
u8g_uint_t xx=0;
const int max_timer = 100;
int timer = 0;
bool boot = true;
static const unsigned char global_icon[] = {0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x00,0xf8,0x00,0x00,0x00,0x03,0xf8,0x01,0x00,0x80,0x03,0xe0,0x03,0x00,0xc0,0x07,0xc0,0x07,0x00,0xe0,0x07,0x00,0x0f,0x00,0xf0,0x07,0x0f,0x1e,0x00,0xf8,0x07,0x1f,0x1c,0x00,0xfc,0x07,0x7e,0x3c,0x00,0xfe,0x07,0x78,0x38,0x00,0xff,0x07,0xf0,0x78,0xff,0xff,0xc7,0xe0,0x71,0xff,0xff,0xc7,0xc3,0xf1,0xff,0xff,0xc7,0xc7,0xf1,0xff,0xff,0x87,0xc7,0xe3,0xff,0xff,0x07,0x8f,0xe3,0xff,0xff,0x07,0x8e,0xe3,0xff,0xff,0x07,0x8e,0xe3,0xff,0xff,0x07,0x8f,0xe3,0xff,0xff,0x87,0xc7,0xe3,0xff,0xff,0xc7,0xc7,0xf1,0xff,0xff,0xc7,0xc3,0xf1,0xff,0xff,0xc7,0xe0,0x71,0x00,0xff,0x07,0xf0,0x78,0x00,0xfe,0x07,0x78,0x38,0x00,0xfc,0x07,0x7e,0x3c,0x00,0xf8,0x07,0x1f,0x1c,0x00,0xf0,0x07,0x0f,0x1e,0x00,0xe0,0x07,0x00,0x0f,0x00,0xc0,0x07,0xc0,0x07,0x00,0x80,0x03,0xe0,0x03,0x00,0x00,0x03,0xf8,0x01,0x00,0x00,0x00,0xf8,0x00,0x00,0x00,0x00,0x38,0x00};
static const unsigned char chrome_icon[] = {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,0x7e,0x00,0x00,0x00,0xc0,0xff,0x03,0x00,0x00,0xf0,0xff,0x0f,0x00,0x00,0xf8,0xff,0x1f,0x00,0x00,0xfc,0xff,0x3f,0x00,0x00,0xfe,0xff,0x7f,0x00,0x00,0xfc,0xff,0xff,0x00,0x00,0xf9,0x07,0x00,0x00,0x80,0xf9,0x00,0x00,0x00,0x80,0x73,0x00,0xfe,0x01,0x80,0x37,0x7e,0xfc,0x01,0xc0,0x27,0xff,0xfc,0x03,0xc0,0x2f,0xff,0xfc,0x03,0xc0,0x0f,0xff,0xf8,0x03,0xc0,0x1f,0xff,0xf8,0x03,0xc0,0x1f,0xff,0xfc,0x03,0xc0,0x3f,0xff,0xfc,0x03,0x80,0x3f,0x7e,0xfc,0x01,0x80,0x7f,0x00,0xfe,0x01,0x80,0xff,0x00,0xff,0x01,0x00,0xff,0x27,0xff,0x00,0x00,0xff,0x9f,0xff,0x00,0x00,0xfe,0x9f,0x7f,0x00,0x00,0xfc,0xcf,0x3f,0x00,0x00,0xf8,0xef,0x1f,0x00,0x00,0xf0,0xe7,0x0f,0x00,0x00,0xc0,0xf7,0x03,0x00,0x00,0x00,0x72,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};
static const unsigned char discord_icon[] = {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,0x78,0x00,0x1e,0x00,0x00,0x7f,0x00,0xfe,0x00,0xc0,0xff,0xff,0xff,0x03,0xe0,0xff,0xff,0xff,0x07,0xe0,0xff,0xff,0xff,0x07,0xf0,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0x0f,0xf8,0xff,0xff,0xff,0x1f,0xf8,0xff,0xff,0xff,0x1f,0xfc,0xff,0xff,0xff,0x3f,0xfc,0xff,0xff,0xff,0x3f,0xfe,0xff,0xff,0xff,0x7f,0xfe,0xff,0xff,0xff,0x7f,0xfe,0x07,0xff,0xe0,0x7f,0xfe,0x03,0xff,0xc0,0x7f,0xfe,0x03,0x7e,0xc0,0xff,0xff,0x03,0x7e,0xc0,0xff,0xff,0x03,0x7e,0xc0,0xff,0xff,0x03,0xff,0xc0,0xff,0xff,0x07,0xff,0xe0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xf3,0xff,0xcf,0x7f,0xfc,0x0f,0x7e,0xf0,0x3f,0xf0,0x0f,0x00,0xf0,0x0f,0xc0,0x0f,0x00,0xf0,0x03,0x00,0x07,0x00,0xe0,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};
static const unsigned char game_icon[] = {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,0xc0,0x1f,0x00,0xf8,0x03,0xe0,0x7f,0x00,0xfe,0x07,0xf0,0xff,0x00,0xff,0x0f,0xf8,0xf9,0xff,0x9f,0x1f,0xf8,0xf8,0xff,0x1f,0x1f,0xf8,0xf8,0xff,0xff,0x1f,0x3c,0xe0,0xff,0xe7,0x3c,0x3c,0xe0,0xff,0xe7,0x3c,0xfc,0xf8,0xff,0x9f,0x3f,0xfc,0xf8,0xff,0x1f,0x3f,0xfc,0xff,0xff,0xff,0x3f,0xfe,0xdf,0xff,0xf9,0x7f,0xfe,0x07,0xff,0xe0,0x7f,0xfe,0x07,0x7f,0xe0,0x7f,0xfe,0x07,0x7e,0xe0,0x7f,0xfe,0x07,0xff,0xe0,0x7f,0xfe,0x0f,0xff,0xf0,0x7f,0xfe,0xff,0xff,0xff,0x7f,0xfe,0xff,0x81,0xff,0x7f,0xfe,0x7f,0x00,0xfe,0x7f,0xfe,0x1f,0x00,0xf8,0x7f,0xfe,0x1f,0x00,0xf8,0x7f,0xfe,0x0f,0x00,0xf0,0x7f,0xfc,0x07,0x00,0xe0,0x3f,0xf8,0x07,0x00,0xe0,0x1f,0xf0,0x01,0x00,0x80,0x0f,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};
static const unsigned char cross[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x01,0xe0,0x03,0x00,0x80,0x07,0xe0,0x07,0x00,0xe0,0x07,0xe0,0x0f,0x00,0xe0,0x07,0xe0,0x1f,0x00,0xf0,0x03,0xc0,0x3f,0x00,0xf8,0x03,0x80,0x3f,0x00,0xfc,0x01,0x00,0x7f,0x00,0xfe,0x00,0x00,0xfe,0x00,0x7e,0x00,0x00,0xfc,0x01,0x3f,0x00,0x00,0xf8,0x83,0x3f,0x00,0x00,0xf0,0xc3,0x1f,0x00,0x00,0xf0,0xe7,0x0f,0x00,0x00,0xe0,0xff,0x07,0x00,0x00,0xc0,0xff,0x07,0x00,0x00,0x80,0xff,0x03,0x00,0x00,0x00,0xff,0x01,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0x80,0xff,0x01,0x00,0x00,0xc0,0xff,0x01,0x00,0x00,0xe0,0xff,0x03,0x00,0x00,0xe0,0xff,0x07,0x00,0x00,0xf0,0xe7,0x07,0x00,0x00,0xf8,0xc3,0x0f,0x00,0x00,0xfc,0x81,0x1f,0x00,0x00,0xfe,0x80,0x3f,0x00,0x00,0x7f,0x00,0x3f,0x00,0x80,0x3f,0x00,0x7e,0x00,0xc0,0x1f,0x00,0xfe,0x00,0xe0,0x0f,0x00,0xfc,0x01,0xf0,0x07,0x00,0xf8,0x03,0xf8,0x03,0x00,0xf8,0x03,0xf8,0x01,0x00,0xf0,0x07,0xf0,0x01,0x00,0xe0,0x07,0x60,0x00,0x00,0xc0,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
static const unsigned char headphones_icon[] = {0xe0,0x03,0x78,0x0f,0x1c,0x1c,0x06,0x30,0x02,0x20,0x01,0x40,0x01,0x40,0x01,0x40,0x06,0x30,0x09,0x48,0x19,0x4c,0x13,0x64,0x22,0x22,0x26,0x32,0x1c,0x1c,0x00,0x00};
static const unsigned char monitor_icon[] = {0x00,0x00,0xff,0xff,0x01,0x80,0xfd,0xbf,0x05,0xa0,0x05,0xa0,0x05,0xa0,0x05,0xa0,0x05,0xa0,0xfd,0xbf,0x01,0x80,0xff,0xff,0xc0,0x03,0xc0,0x03,0xf0,0x0f,0x00,0x00};
const int NUM_SLIDERS = 5;
const int NUM_AUDIO = 4;
const byte PotOne = 0;
const byte PotTwo = 1;
const byte PotThree = 2;
const byte PotFour = 3;
const int analogInputs[NUM_SLIDERS] = {PotOne, PotTwo, PotThree, PotFour, PotFour};
const int potMax = 1023.0; // NEED to make this a float else division will be integer
//const char volImages[NUM_SLIDERS-1] = {global_icon, chrome_icon, discord_icon, game_icon};
//const char audImages[] = {monitor_icon,headphones_icon};
const String audSources[] = {"Innoview","Acer Nitro","Headphones","Headset"};
const String audTypes[] = {"Speakers","Bluetooth"};
int analogSliderValues[NUM_SLIDERS];
void gauge(uint8_t ) {
// show digital value and align its position
u8g.setFont(u8g_font_profont22);
if (curpot != NUM_SLIDERS-1) {
u8g.setPrintPos(85,58);
if (w<10){
u8g.print("0");
}
if (w>99) {
u8g.setPrintPos(80,58);
}
u8g.print(w);
u8g.print("%");
int frameX[] = {2, 24, 42, 60}; // x values for all borders
for (int i = 0; i < NUM_SLIDERS-1; i++) {
u8g.drawFrame(frameX[i],4,15,54);
float boxProg = 48*((float)analogSliderValues[i]/potMax);
if (boxProg >= 1) { // draw an empty box when volume = 0
u8g.drawBox(frameX[i]+3, 7+(48-boxProg), 9, boxProg);
}
else if (i == curpot) { // draw an x over the image when volume = 0 and that image is displayed
u8g.drawXBM(82, 4, 40, 41, cross);
}
}
//u8g.drawXBM(82, 4, 40, 34, volImages[curpot]);
}
else {
int chanNum = analogRead(A6);
for (int i = 0; i < NUM_AUDIO; i++) {
if (curaud!= i and chanNum< (i+1)*(potMax/NUM_AUDIO) and chanNum >= i*(potMax/NUM_AUDIO)) {
curaud = i;
break;
}
}
u8g.drawFrame(4, 14, 120, 23);
u8g.drawLine(4, 11, 123, 11);
u8g.setFont(u8g_font_chikita);
u8g.setFont(u8g_font_chikita);
u8g.setPrintPos(9, 31);
u8g.print(audSources[curaud]);
int closeBox[] = {15,44,73,103};
int openBox[] = {10,39,69,98};
int numBox[] = {15,44,74,103};
for (int i = 0; i < NUM_AUDIO; i++) {
if (curaud == i) {
u8g.drawFrame(openBox[i],41,19,19);
u8g.setPrintPos(numBox[i],56);
u8g.print(i+1);
}
else {
u8g.drawBox(closeBox[i],46,9,9);
}
}
int source = 0;
if (curaud/(float)NUM_AUDIO >= 0.5) {
source = 1;
}
u8g.setPrintPos(4,10);
u8g.print(audTypes[source]);
//u8g.drawXBM(104, 18, 16, 16, audImages[source]);
}
}
void setup(void) {
u8g.setFont(u8g_font_chikita);
u8g.setColorIndex(1);
// assign default color value
if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
u8g.setColorIndex(255);
}
else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
u8g.setColorIndex(3);
}
else if ( u8g.getMode() == U8G_MODE_BW ) {
u8g.setColorIndex(1);
}
else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
u8g.setHiColorByRGB(255,255,255);
}
Serial.begin(115200);
}
void loop(void) {
String builtString = String("");
for (int i = 0; i < NUM_SLIDERS; i++) {
c = analogRead(analogInputs[i]);
if ( analogSliderValues[i] != c and boot == false) {
curpot = i;
timer = max_timer;
}
analogSliderValues[i] = c;
builtString += String((int)analogSliderValues[i]);
if (i < NUM_SLIDERS - 1) {
builtString += String("|");
}
}
p = analogSliderValues[curpot];
w = map(p,0,1023,0,100);
// show needle and dial
{
u8g.firstPage();
do {
gauge(w);
}
while( u8g.nextPage() );
}
if (timer > 0) {
timer -= 1;
}
else {
timer = 0;
if (curpot != 0) {
curpot = 0;
}
}
Serial.println(builtString);
// Bluetooth testing
//Serial.read();
//Serial.println(digitalRead(12));
// printSliderValues(); // is only for debug, remove in actual
boot = false; // set the boot value (true when it turns on only) to false
}
void printSliderValues() {
for (int i = 0; i < NUM_SLIDERS; i++) {
String printedString = String("Slider #") + String(i + 1) + String(": ") + String(analogSliderValues[i]) + String(" mV");
Serial.write(printedString.c_str());
if (i < NUM_SLIDERS - 1) {
Serial.write(" | ");
} else {
Serial.write("\n");
}
}
}