//
// **********************************************
// * *
// * BOB SNIFFER *
// * *
// **********************************************
//
#include <SPI.h>
#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
#define OLED_RESET -1 // Reset pin
#define SCREEN_ADDRESS 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
char myData[19]; //'*' not saved; 18 chars are saved, last one for null
int counter = 0;
int red_button = 15;
int sniff = 13; // D5 8266 D14 ESP32
int test = 12; // D6 8266 D13 ESP32
int cal = 14; // D7 8266 D12 ESP32
void setup()
{
Serial.begin(9600);
pinMode (sniff, INPUT);
pinMode (test, INPUT);
pinMode (cal, INPUT);
pinMode (red_button, INPUT);
delay(100);
// initialize the OLED object
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
//Serial.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed, loop forever
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(10, 1);
display.println(" BOB DEBUG TOOL v24");
display.display();
delay(5000);
}
void loop()
{
Check_Mode_Switch();
}
void Check_Mode_Switch()
{
//
// Read Rotary Switch
//
if (digitalRead(sniff) == HIGH)
{
SNIFFER();
}
if (digitalRead(test) == HIGH)
{
TEST();
}
if (digitalRead(cal) == HIGH)
{
CAL();
}
}
void SNIFFER()
{
counter = 0;
//
//
display.clearDisplay();
display.setCursor(0, 1);
display.println(" BOB SNIFFER ");
display.display();
go: //
byte n = Serial.available();
if (n != 0)
{
char ch = Serial.read();
if (ch == '*')
{
byte m = Serial.readBytes(myData, 19); // Read 19 characters after an * is found
myData[m] = '\0'; //inset null-byte
display.clearDisplay();
display.setCursor(0,1);
display.println(" BOB SNIFFER ");
display.setCursor(10, 20);
display.println(myData);
display.display();
delay(200);
//
// Data Extraction
//
char X;
int game_status;
int fieldsParsed = sscanf(myData, "%c;%d", &X, &game_status);
if (game_status == 3)
{
display.setCursor(0, 1);
display.println(" BOB SNIFFER ");
display.setCursor(10, 40);
display.println(" BALL IN RIM");
display.display();
delay(200);
}
if (game_status == 4)
{
display.setCursor(0, 1);
display.println(" BOB SNIFFER ");
display.setCursor(10, 40);
display.println(" NO MORE BETS");
display.display();
delay(200);
}
if (game_status == 5)
{
display.setCursor(0, 1);
display.println(" BOB SNIFFER ");
display.setCursor(45, 40);
display.setTextSize(2);
display.print(myData[8]);
display.println(myData[9]);
display.setTextSize(1);
display.display();
delay(500);
}
}
}
counter = counter+1;
if (counter < 50000)
{
goto go;
}
}
void TEST()
//
// SENSOR TEST ROUTINE
//
{
//go2:
display.clearDisplay();
display.setCursor(0, 1);
display.println(" SENSOR TESTER ");
display.println("");
display.println(" PLACE BALL IN ZERO");
display.println("");
display.println(" Press red button");
display.println(" to start");
display.display();
if (digitalRead(red_button) == HIGH)
{
Serial.print ("*SP"); // "SP
display.clearDisplay();
display.setCursor(0, 1);
display.println(" SENSOR TESTER ");
display.display();
delay(5000);
go2:
byte n = Serial.available();
if (n != 0)
{
char ch = Serial.read();
if (ch == 'O')
{
Serial.print ("Got OK");
byte m = Serial.readBytes(myData, 19); // Read 19 characters after an * is found
myData[m] = '\0'; //inset null-byte
display.clearDisplay();
display.setCursor(0, 1);
display.println(" SENSOR TESTER ");
display.setCursor(10, 20);
display.println(myData);
display.display();
delay(200);
//
// Data Extraction
//
}
//goto go2;
}
//delay(2000);
goto go2;
}
}
void CAL()
//
// SENSOR CALIBRATION ROUTINE
//
{
go2: display.clearDisplay();
display.setCursor(0, 1);
display.println(" SENSOR CAL");
display.setCursor(10, 20);
display.println("DO NOT USE ON LIVE");
display.println(" TABLE !");
display.println("");
display.println(" Press red button");
display.println(" to start");
display.display();
//Serial.print(digitalRead(red_button));
if (digitalRead(red_button) == HIGH)
{
display.clearDisplay();
display.setCursor(0, 1);
display.println(" SENSOR CAL");
display.setCursor(10, 20);
display.println("UNDER DEVELOPMENT");
display.display();
delay (10000);
}
}