273 lines
7.4 KiB
C++
273 lines
7.4 KiB
C++
//======================================================
|
|
// OLED DISPLAY
|
|
//======================================================
|
|
// LIBRARY INCLUDE
|
|
//------------------------------------------------------
|
|
|
|
// Include Libraries
|
|
#include <Wire.h>
|
|
#include <SSD1306Wire.h>
|
|
|
|
// Display Instance
|
|
SSD1306Wire display(0x3c, 21, 22);
|
|
|
|
//------------------------------------------------------
|
|
// OLED INITIALIZATION
|
|
//------------------------------------------------------
|
|
|
|
void OLED_INIT() {
|
|
display.init();
|
|
display.flipScreenVertically();
|
|
display.setFont(ArialMT_Plain_10);
|
|
}
|
|
|
|
//------------------------------------------------------
|
|
// OLED CLEAR DISPLAY
|
|
//------------------------------------------------------
|
|
|
|
void OLED_CLEAR() {
|
|
display.clear();
|
|
}
|
|
|
|
//------------------------------------------------------
|
|
// OLED CLEAN DISPLAY
|
|
//------------------------------------------------------
|
|
|
|
void OLED_CLEAN() {
|
|
OLED_CLEAR();
|
|
OLED_SHOW();
|
|
}
|
|
|
|
//------------------------------------------------------
|
|
// OLED SHOW NEW DATA
|
|
//------------------------------------------------------
|
|
|
|
void OLED_SHOW() {
|
|
display.display();
|
|
}
|
|
|
|
//------------------------------------------------------
|
|
// OLED DISPLAY KICKER WELCOME MESSAGE
|
|
//------------------------------------------------------
|
|
|
|
void KICKER_LOGO() {
|
|
// Starting The First Code
|
|
OLED_CLEAR();
|
|
drawTextCenter(128/2, 5, 3, "TAKEONE");
|
|
drawTextCenter(128/2, 30, 1, " - T E C H N O L O G Y - ");
|
|
drawTextCenter(128/2, 43, 2, "<< KICKER >>");
|
|
OLED_SHOW();
|
|
}
|
|
|
|
//------------------------------------------------------
|
|
// OLED DISPLAY KICKER POWERING OFF MESSAGE
|
|
//------------------------------------------------------
|
|
|
|
void OLED_POWERING_DOWN() {
|
|
dualcomm(POWEROFF);
|
|
OLED_CLEAR();
|
|
drawTextCenter(128/2, 5, 3, "POWER");
|
|
drawTextCenter(128/2, 30, 1, "- T U R N I N G O F F -");
|
|
drawTextCenter(128/2, 43, 2, "SEE YOU AGAIN");
|
|
OLED_SHOW();
|
|
BOOST_OFF;
|
|
delay(2000);
|
|
OLED_CLEAN();
|
|
delay(250);
|
|
POWER_OFF;
|
|
}
|
|
|
|
//------------------------------------------------------
|
|
// OLED Display Text
|
|
//------------------------------------------------------
|
|
|
|
void drawTextFlowDemo(String Text) {
|
|
display.setFont(ArialMT_Plain_10);
|
|
display.setTextAlignment(TEXT_ALIGN_LEFT);
|
|
display.drawStringMaxWidth(0, 0, 128, Text);
|
|
}
|
|
|
|
//------------------------------------------------------
|
|
// OLED LEFT TEXT Display
|
|
//------------------------------------------------------
|
|
|
|
void drawTextLeft() {
|
|
display.setFont(ArialMT_Plain_10);
|
|
display.setTextAlignment(TEXT_ALIGN_LEFT);
|
|
display.drawString(0, 10, "Left aligned (0,10)");
|
|
}
|
|
|
|
//------------------------------------------------------
|
|
// OLED CENTER TEXT Display
|
|
//------------------------------------------------------
|
|
|
|
void drawTextCenter(int X, int Y, int Size, String Text) {
|
|
//display.setFont(ArialMT_Plain_10);
|
|
|
|
if(Size == 1) {
|
|
display.setFont(ArialMT_Plain_10);
|
|
} else if(Size == 2) {
|
|
display.setFont(ArialMT_Plain_16);
|
|
} else if(Size == 3) {
|
|
display.setFont(ArialMT_Plain_24);
|
|
} else {
|
|
display.setFont(ArialMT_Plain_10);
|
|
}
|
|
|
|
display.setTextAlignment(TEXT_ALIGN_CENTER);
|
|
display.drawString(X, Y, Text);
|
|
}
|
|
|
|
//------------------------------------------------------
|
|
// OLED RIGHT TEXT DISPLAY
|
|
//------------------------------------------------------
|
|
|
|
// OLED Display
|
|
void drawTextRight() {
|
|
display.setFont(ArialMT_Plain_10);
|
|
display.setTextAlignment(TEXT_ALIGN_RIGHT);
|
|
display.drawString(128, 33, "Right aligned (128,33)");
|
|
}
|
|
|
|
//------------------------------------------------------
|
|
// OLED DRAW RECTANGLE
|
|
//------------------------------------------------------
|
|
|
|
void drawRectDemo() {
|
|
// Draw a pixel at given position
|
|
for (int i = 0; i < 10; i++) {
|
|
display.setPixel(i, i);
|
|
display.setPixel(10 - i, i);
|
|
}
|
|
display.drawRect(12, 12, 20, 20);
|
|
|
|
// Fill the rectangle
|
|
display.fillRect(14, 14, 17, 17);
|
|
|
|
// Draw a line horizontally
|
|
display.drawHorizontalLine(0, 40, 20);
|
|
|
|
// Draw a line horizontally
|
|
display.drawVerticalLine(40, 0, 20);
|
|
}
|
|
|
|
//------------------------------------------------------
|
|
// OLED DRAW CIRCLE
|
|
//------------------------------------------------------
|
|
|
|
void drawCircleDemo() {
|
|
for (int i=1; i < 8; i++) {
|
|
display.setColor(WHITE);
|
|
display.drawCircle(32, 32, i*3);
|
|
if (i % 2 == 0) {
|
|
display.setColor(BLACK);
|
|
}
|
|
display.fillCircle(96, 32, 32 - i* 3);
|
|
}
|
|
}
|
|
|
|
//------------------------------------------------------
|
|
// OLED DRAW PROGRESS BAR
|
|
//------------------------------------------------------
|
|
|
|
void drawProgressBarDemo(int Value) {
|
|
int progress = Value;
|
|
// draw the progress bar
|
|
display.drawProgressBar(0, 50, 120, 10, progress);
|
|
|
|
// draw the percentage as String
|
|
display.setTextAlignment(TEXT_ALIGN_CENTER);
|
|
display.drawString(64, 35, String(progress) + "%");
|
|
}
|
|
|
|
//------------------------------------------------------
|
|
// I2C DECIVES SCANNER
|
|
//------------------------------------------------------
|
|
|
|
void scanI2C()
|
|
{
|
|
byte error, address;
|
|
int nDevices;
|
|
|
|
Serial.println(" -> Scanning I2C Devices ...");
|
|
|
|
nDevices = 0;
|
|
for(address = 1; address < 127; address++ )
|
|
{
|
|
// The i2c_scanner uses the return value of
|
|
// the Write.endTransmisstion to see if
|
|
// a device did acknowledge to the address.
|
|
Wire.beginTransmission(address);
|
|
error = Wire.endTransmission();
|
|
|
|
if (error == 0)
|
|
{
|
|
Serial.print(" --> Device Found At Address 0x");
|
|
if (address<16)
|
|
Serial.print("0");
|
|
Serial.print(address,HEX);
|
|
Serial.println(" !");
|
|
|
|
nDevices++;
|
|
}
|
|
else if (error==4)
|
|
{
|
|
Serial.print(" --> Unknown error at address 0x");
|
|
if (address<16)
|
|
Serial.print("0");
|
|
Serial.println(address,HEX);
|
|
}
|
|
}
|
|
if (nDevices == 0)
|
|
Serial.println(" --> No I2C devices found\n");
|
|
else
|
|
Serial.println(" --> done");
|
|
}
|
|
|
|
//------------------------------------------------------
|
|
// WAITING FOR BLUETOOTH CONNECTION
|
|
//------------------------------------------------------
|
|
|
|
void OLED_BLUETOOTH_MODE()
|
|
{
|
|
// Starting The First Code
|
|
OLED_CLEAR();
|
|
drawTextCenter(128/2, 5, 3, "KICKER");
|
|
drawTextCenter(128/2, 30, 1, " - B L U E T O O T H - ");
|
|
if(BLUETOOTH_STATUS == true) {
|
|
drawTextCenter(128/2, 43, 2, "< CONNECTED >");
|
|
} else {
|
|
drawTextCenter(128/2, 43, 2, "< WAITING >");
|
|
}
|
|
OLED_SHOW();
|
|
}
|
|
|
|
//------------------------------------------------------
|
|
// WAITING FOR BLUETOOTH CONNECTION
|
|
//------------------------------------------------------
|
|
|
|
void OLED_STANDALONE_MODE()
|
|
{
|
|
// Starting The First Code
|
|
OLED_CLEAR();
|
|
drawTextCenter(128/2, 5, 3, "KICKER");
|
|
drawTextCenter(128/2, 30, 1, " - S T A N D A L O N E - ");
|
|
drawTextCenter(128/2, 43, 2, "< MODE >");
|
|
OLED_SHOW();
|
|
}
|
|
|
|
//------------------------------------------------------
|
|
// GAME SLIDER SELECTOR
|
|
//------------------------------------------------------
|
|
|
|
void GAME_PAGE(uint8_t MenuNumber, String Title) {
|
|
if(DISPLAY_CHANGED == false) {
|
|
OLED_CLEAR();
|
|
drawTextCenter(128/2, 5, 3, "< GAME #" + String(MenuNumber) >);
|
|
drawTextCenter(128/2, 30, 1, " - " + Title + " - ");
|
|
drawTextCenter(128/2, 43, 2, "<< SELECT >>");
|
|
OLED_SHOW();
|
|
DISPLAY_CHANGED = true;
|
|
}
|
|
}
|