/*
A simple Pong game.
https://notabug.org/Maverick/WokwiPong
Based on Arduino Pong by eholk
https://github.com/eholk/Arduino-Pong
*/
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C // You may need to change this address depending on your OLED module
//display stuff
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
int highlightedBar = 3; // Change this value to highlight a different bar
bool barSelected = false;
int highlightedSetting = 0;
int ButtonHeld = 0;
int refreshInt = 20;
//Settings
String ver = "2024 BARKUS MFG LLC";
enum ScreenSel { //which screen we are on
MAIN,
SETTINGS,
PINREMAP
};
ScreenSel screenSel = SETTINGS;
bool settingSelected = false;
int scroll = -22;
int pinRemapSel = 0;
int pindex = 0;
bool pinSelected = 0;
int scrollLimit[] = { -42, 38 };
int settings = 8;
int highlightedsetting = 0;
String settingParams[] = { "Back", "Refresh", "Release Thresh", "Press Thresh", "Poll Tester", "Save Settings", "!!Reset All!!", "Inputs", "Pin Remap" };
int autoSaveInt = 10000;
int autoSaveCounter = 0;
int resetCounter = 0;
int possiblePins[] = {A0, A1, A2, A3, A6, A7, 2, 1};
unsigned long lastInput;
//savingstuff
//rotary knob stuff
int oldPos = 0;
bool release = true;
//test poll
bool flipper = false;
bool testPoll = false;
//////////////////////////////////////////
/**/uint8_t inputPins[] = {A1, A2, A3, A4, A5, A4, 8, 9};//
//////////////////////////////////////////
uint8_t inputs = 4;
int threshVal[] = {200, 400, 200, 200, 200, 200};
int sensVal[] = {400, 720, 30, 50, 300, 70};
bool bOn[] = {false, false, false, false, true, false};
//Adjusting these values below may help with jitter inputs (Lightly pressing the tile and getting 10s to 100s of button presses)
int releaseThresh = 10; //Keep this below press Thresh, default = 10
int pressThresh = 15; //Keep this above release Thresh, default = 15
const unsigned char settmap [] PROGMEM = {
0x24, 0x00, 0x81, 0x18, 0x18, 0x81, 0x00, 0x24
};
void setup()
{
display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
}
void loop()
{
updateDisplay();
}
void updateDisplay() {
//Clear display
display.clearDisplay();
if (screenSel == MAIN) {
int barWidth = 128 / inputs - 4;
//First draw the selection box
if (highlightedBar != inputs) {
display.drawRect(highlightedBar * (barWidth + 4), 0, barWidth + 4, 54, WHITE);
}
//display.drawRect(x + 6+ thickness, y + thickness, width - 2 * thickness, height - 2 * thickness, BLACK);
//Draw input data bars
for (int i = 0; i < inputs; i++) {
int barHeights = (sensVal[i] / 19);
int blipPositions = (threshVal[i] / 19);
display.fillRect(i * (barWidth + 4) + 3, 54 - barHeights, barWidth - 2, barHeights, WHITE);
int blipColor = WHITE;
if (barHeights > blipPositions) {
blipColor = BLACK;
}
display.fillRect(i * (barWidth + 4) + 3, 54 - blipPositions, barWidth - 2, 2, blipColor);
}
//Draw buttons
display.setTextSize(0);
display.fillRect(0, 54, 128, 10, WHITE);
int selColor = BLACK;
int startColor = BLACK;
if (bOn[6]) {
startColor = WHITE;
} else {
startColor = BLACK;
}
if (bOn[7]) {
selColor = WHITE;
} else {
selColor = BLACK;
}
display.fillRoundRect(1, 55, 50, 8, 2, selColor);
display.setCursor(14, 56);
display.setTextColor(!selColor);
display.println("BACK");
display.fillRoundRect(128 - 51, 55, 50, 8, 2, startColor);
display.setCursor(88, 56);
display.setTextColor(!startColor);
display.println("START");
//Draw settings icon
if (highlightedBar == inputs) {
display.fillRect(60, 55, 8, 8, BLACK);
display.drawRect(58, 53, 12, 12, BLACK);
display.drawBitmap(60, 55, settmap, 8, 8, WHITE);
} else {
display.fillRect(60, 55, 8, 8, BLACK);
display.drawBitmap(60, 55, settmap, 8, 8, WHITE);
}
}
else if (screenSel == SETTINGS) { //display settings
//Setup
display.setTextColor(WHITE);
display.drawRect(0, 26, 128, 11, WHITE);
display.setTextSize(0);
//Back
display.setCursor(5, scroll - 10);
display.println(settingParams[0]);
//Setting 0
display.setCursor(5, scroll + 0);
display.println(settingParams[1]);
display.setCursor(100, scroll + 0);
display.println(refreshInt);
//Setting 1
display.setCursor(5, scroll + 10);
display.println(settingParams[2]);
display.setCursor(100, scroll + 10);
display.println(releaseThresh);
//Setting 2
display.setCursor(5, scroll + 20);
display.println(settingParams[3]);
display.setCursor(100, scroll + 20);
display.println(pressThresh);
//Setting 3
display.setCursor(5, scroll + 30);
display.println(settingParams[4]);
display.setCursor(100, scroll + 30);
display.println(testPoll);
//Setting 4
display.setCursor(5, scroll + 40);
display.println(settingParams[5]);
//Setting 5
display.setCursor(5, scroll + 50);
display.println(settingParams[6]);
//Setting 6
display.setCursor(5, scroll + 60);
display.println(settingParams[7]);
display.setCursor(100, scroll + 60);
display.println(inputs);
//Setting 7
display.setCursor(5, scroll + 70);
display.println(settingParams[8]);
//INFO
display.setCursor(5, scroll + 90);
display.println(ver);
}
else if (screenSel == PINREMAP) {
//setup
//draw cursor
display.setTextColor(WHITE);
display.drawRect(pinRemapSel * 16, 50, 17, 12, WHITE);
display.drawRect(pinRemapSel * 16, 18, 17, 12, WHITE);
display.setTextSize(0);
//draw labels
display.setCursor(43, 5);
display.println("OUTPUT:");
display.setCursor(5, 20);
display.println("1");
display.setCursor(23, 20);
display.println("2");
display.setCursor(39, 20);
display.println("3");
display.setCursor(53, 20);
display.println("4");
display.setCursor(69, 20);
display.println("5");
display.setCursor(85, 20);
display.println("6");
display.setCursor(99, 20);
display.println("ST");
display.setCursor(114, 20);
display.println("SE");
display.setCursor(3, 35);
display.println("CORRESPONDING PIN:");
display.setCursor(2, 52);
display.println(inputPins[0]);
display.setCursor(21, 52);
display.println(inputPins[1]);
display.setCursor(37, 52);
display.println(inputPins[2]);
display.setCursor(51, 52);
display.println(inputPins[3]);
display.setCursor(67, 52);
display.println(inputPins[4]);
display.setCursor(83, 52);
display.println(inputPins[5]);
display.setCursor(97, 52);
display.println(inputPins[6]);
display.setCursor(112, 52);
display.println(inputPins[7]);
}
//Render result
display.display();
}