OK did some updates
Code:
/*Libraries provided by adafruit written by Lady Ada Fried.
*Please stick to adafruit products as chinese knock offs are very,
*very, very, problematic.
* code for bar courtesy of:
* https://forum.arduino.cc/t/tft-progress-bar-wont-go-back-down/989189
* some code pulled from isolation motion tracker pulled from:
* https://www.instructables.com/Arduino-Motion-Tracker-From-Alien-Isolation/?fbclid=IwAR2P0H8tUwBisNGaP4C2vccz-fbBOlxxfdm8EIJJEHgAZnKOtgemeBjAZ3M
* help found on arduino forums at https://arduino.cc
*
*
*/
// Include the Bounce2 library found here :
// https://github.com/thomasfredericks/Bounce2
#include <Bounce2.h>
#include <SPI.h>
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include <LcdProgressBar.h>
#include <LiquidCrystal.h>
// For the Adafruit shield, these are the default.
#define TFT_MISO 8
#define TFT_DC 9
#define TFT_CS 10
#define TFT_MOSI 11
#define TFT_CLK 13
// the colors are in a RGB565 format, so to get it you first need to grab it as a RGB888 and convert
//go here
//https://imagecolorpicker.com/en
//then here
//http://www.barth-dev.de/online/rgb565-color-picker/
// Assign human-readable names to some common 16-bit color values:
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define DARKGREEN 0x03E0
#define OLIVE 0x7BE0
#define GREENYELLOW 0xAFE5
#define TEAL 0x263F
// button pins
#define BUTTON_PIN_1 18
#define BUTTON_PIN_2 19
// pot pins are pins 14 and 15
Bounce debouncer1 = Bounce();
Bounce debouncer2 = Bounce();
// integer declarations
int rangelow;
int rangehigh;
int g1low = 50;
int g1high = 50;
int center;
//TFT TFTscreen = TFT(cs, dc, rst);
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_MISO);
void setup() {
pinMode(A0, INPUT);
tft.begin();
tft.fillScreen(BLACK);
tft.setRotation(1); //this sets 0,0 as the top left corner
txt();
boot1();
boot2();
// tft.setRotation(0);
tft.fillScreen(BLACK);
tft.setRotation(1);
// button initialization
pinMode(BUTTON_PIN_1,INPUT_PULLUP); debouncer1.attach(BUTTON_PIN_1); debouncer1.interval(5);
pinMode(BUTTON_PIN_2,INPUT_PULLUP); debouncer2.attach(BUTTON_PIN_2); debouncer2.interval(25);
// sets up random number generator for game1 to game 2 transition
randomSeed(analogRead(A3));
center = random(150, 950);
int myHeight = tft.height();
int myWidth = tft.width();
}
void loop() {
// int myHeight = tft.height();
//int myWidth = tft.width();
// int bar = map(analogRead(A0), 0, 1023, 0, 308);
//math for range sweetspot logic, center is declared in setup
rangelow = center - g1low;
rangehigh = center + g1high;
// comment out the bottom two lines and replace them with the below line to aid in calibrating your setup
// calibration();
if (rangelow < analogRead(A0) && < analogRead(A0) < rangehigh) { game2();} // tft.fillRect(230, 40, 20, 20, OLIVE); }
else { game1(); } //tft.fillRect(230, 40, 20, 20, BLACK);}
// declarations for buttons
debouncer1.update(); debouncer2.update(); int value1 = debouncer1.read(); int value2 = debouncer2.read();
delay(100);
}
calibration()
{
int myHeight = tft.height();
int myWidth = tft.width();
int bar = map(analogRead(A0), 0, 1023, 0, 308);
tft.fillRect(6, 80, bar, 44, RED);
tft.fillRect(bar, 80, 308 - bar, 44, BLACK);
tft.fillRect(0, 20, myWidth, 5, BLACK);
// draws pot number reading
tft.setCursor(80,40);
tft.setTextColor(RED);
tft.setTextSize(3);
tft.println(analogRead(A0));
// draws pot 2 number reading
tft.setCursor(160,40);
tft.setTextColor(RED);
tft.setTextSize(3);
tft.println(analogRead(A1));
// clears button status
tft.fillRect(80, 140, 100, 30, BLACK);
tft.fillRect(80, 180, 100, 30, BLACK);
// add rendering pause
delay(100);
// clears drawings
tft.fillRect(bar, 20, 20, 5, WHITE);
tft.fillRect(80, 40, 200, 30, BLACK);
game1();
//math for range sweetspot logic
rangelow = center - g1low;
rangehigh = center + g1high;
if (rangelow < analogRead(A0) && < analogRead(A0) < rangehigh) { tft.fillRect(230, 40, 20, 20, OLIVE); }
else {tft.fillRect(230, 40, 20, 20, BLACK);}
// declarations for buttons
debouncer1.update(); debouncer2.update(); int value1 = debouncer1.read(); int value2 = debouncer2.read();
// draws button 2 status
tft.setCursor(160,140);
tft.setTextColor(RED);
tft.setTextSize(3);
tft.println(value2);
// draws button 1 status
tft.setCursor(80,140);
tft.setTextColor(OLIVE);
tft.setTextSize(3);
tft.println(value1);
// draws button 2 status
tft.setCursor(160,180);
tft.setTextColor(OLIVE);
tft.setTextSize(3);
tft.println(rangelow);
// draws button 1 status
tft.setCursor(80,180);
tft.setTextColor(OLIVE);
tft.setTextSize(3);
tft.println(rangehigh);
// clears text
}
void txt() {//Starting :)
tft.fillScreen(BLACK);
tft.setCursor(60, 20);
tft.setTextColor(WHITE);
tft.setTextSize(5);
tft.println("B2-LAB");
tft.setCursor(20, 80);
tft.setTextColor(GREEN);
tft.setTextSize(3);
tft.println("MOTION-TRACKER");
tft.setCursor(10,130);
tft.setTextColor(RED);
tft.setTextSize(2);
tft.println("^VERTICAL WHEN OPERATING^");
tft.setCursor(60, 150);
tft.setTextColor(GREEN);
tft.setTextSize(2);
tft.print("Calibrate Sensors");
tft.setCursor(10, 170);
tft.setTextSize(3);
for(int i=0;i<4;i++)
{
tft.print(".");
delay(1000);
}
}
void boot1() {
int myHeight = tft.height();
int myWidth = tft.width();
byte progress = myWidth/8;
tft.fillScreen(BLACK);
tft.setCursor(20, 10);
tft.setTextColor(GREEN);
tft.setTextSize(6);
tft.println("SEEGSON");
tft.drawRect(myWidth/8, myHeight*3/5, myWidth/2, 50, GREEN);
for(int i=0;i<40;i++) {
tft.fillRect(myWidth/8, myHeight*3/5, progress, 50, GREEN);
tft.setTextSize(2);
tft.setCursor(10, 100);
tft.print("Progress = ");
tft.setTextSize(2);
tft.setCursor(140, 100);
tft.println(progress);
delay(20);
tft.fillRect(140, 100, 50, 20, BLACK);
progress += 5;
delay(300);
}
}
void boot2() {
tft.fillScreen(BLACK);
int myHeight = tft.height();
int myWidth = tft.width();
tft.fillScreen(BLACK);
tft.setCursor(myWidth*1/16, myHeight*9/12);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.print("Please wait");
tft.drawRect(myWidth/2, myHeight*1/5, 5, 20, WHITE);
delay(200);
tft.drawRect(myWidth/2, myHeight*1/5, 5, 20, BLACK);
tft.drawLine(myWidth*7/16, myHeight*3/12, myWidth*9/16, myHeight*1/12, WHITE);
delay(200);
tft.drawLine(myWidth*7/16, myHeight*3/12, myWidth*9/16, myHeight*1/12, BLACK);
}
void game2() {
int myHeight = tft.height();
int myWidth = tft.width();
// MAKES BACKGROUND
tft.fillScreen(TEAL);
// sets text static display pieces
tft.setCursor(myWidth*2/16, myHeight*1/12);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.print("SYSTEM OVERRIDE");
tft.setCursor(myWidth*3/16, myHeight*11/12);
tft.setTextColor(WHITE);
tft.setTextSize(1);
tft.print("SECURITY FREQUENCY MATCH");
tft.setCursor(myWidth*3/16, myHeight*12/12-6);
tft.setTextColor(WHITE);
tft.setTextSize(1);
tft.print("V2.34 SYSTEM TEST");
// the minigame border
tft.drawRect(3, myHeight*3/12, myWidth-6, myHeight*6/12, WHITE);
tft.drawRect(6, myHeight*3/12, myWidth-9, myHeight*6/12, WHITE);
}
void game1() {
int myHeight = tft.height(); int myWidth = tft.width();
//I ended up having to separate out remaps for each side of the slider bar
int bordw = map(analogRead(A0), 0, 1023, 0, 1023);
int bordt = map(analogRead(A0), 0, 256, 0, myWidth);
int bordrh = map(analogRead(A0), 256, 512, 0, myHeight);
int bordb = map(analogRead(A0), 512, 768, myWidth, 0);
int bordlh = map(analogRead(A0), 768, 1023, myHeight, 0);
//below greyed out was used to figure out logic of slider bar for game 1
/*
// top border, right, bottom, left border bar
if (1 < bordw < 256){ tft.fillRect(bordt, 0, 20, 5, WHITE); delay(100); tft.fillRect(0, 0, myWidth, 5, BLACK); }
if (257 < bordw < 512){ tft.fillRect(myWidth -5, bordrh, 5, 20, WHITE); delay(100); tft.fillRect(myWidth -5, 0, 5, myHeight, BLACK); }
if (512 < bordw < 768){ tft.fillRect(bordb, (myHeight - 5), 20, 5, WHITE); delay(100); tft.fillRect(0, (myHeight - 5), myWidth, 5, BLACK); }
if (768 < bordw < 1023){ tft.fillRect(0, bordlh, 5, 20, WHITE); delay(100); tft.fillRect(0, 0, 5, myHeight, BLACK); }
*/
// after figuring out logic I tested to see if just simplifying and condensing the statements without if cases would work (it worked.)
tft.fillRect(bordt, 0, 20, 5, WHITE);
tft.fillRect(myWidth -5, bordrh, 5, 20, WHITE);
tft.fillRect(bordb, (myHeight - 5), 20, 5, WHITE);
tft.fillRect(0, bordlh, 5, 20, WHITE);
delay(50);
tft.fillRect(0, 0, 5, myHeight, BLACK);
tft.fillRect(0, 0, myWidth, 5, BLACK);
tft.fillRect(myWidth -5, 0, 5, myHeight, BLACK);
tft.fillRect(0, (myHeight - 5), myWidth, 5, BLACK);
}