/*********
Complete project details at https://randomnerdtutorials.com
This is an example for our Monochrome OLEDs based on SSD1306 drivers. Pick one up today in the adafruit shop! ------> http://www.adafruit.com/category/63_98
This example is for a 128x32 pixel display using I2C to communicate 3 pins are required to interface (two I2C and one reset).
Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries, with contributions from the open source community. BSD license, check license.txt for more information All text above, and the splash screen below must be included in any redistribution.
*********/
#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
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define LOGO_HEIGHT 64
#define LOGO_WIDTH 128
const unsigned char logo_bmp [] PROGMEM = {
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, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x3f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x79, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xf9, 0xf0, 0x03, 0xe0, 0x78, 0x7f, 0xff, 0xff, 0xf9, 0xe0, 0x00, 0x0e, 0x01, 0xff, 0xc0,
0x01, 0xf0, 0xf8, 0x03, 0xf0, 0x7c, 0x7f, 0xff, 0xff, 0xf9, 0xe0, 0x00, 0x1e, 0x01, 0xff, 0xe0,
0x07, 0xe0, 0x7e, 0x03, 0xf0, 0x7c, 0x7f, 0xff, 0xff, 0xf9, 0xe0, 0x00, 0x1e, 0x01, 0xff, 0xf0,
0x1f, 0xc0, 0x3f, 0x03, 0xf8, 0x7c, 0x7f, 0xff, 0xff, 0xf9, 0xe0, 0x00, 0x3f, 0x01, 0xff, 0xf8,
0x3f, 0x00, 0x0f, 0xc3, 0xf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0, 0x03, 0xff, 0xf9, 0xf1, 0xf0,
0x00, 0x0f, 0x3c, 0xf3, 0xe1, 0xfc, 0x7f, 0xfc, 0x1f, 0x01, 0xff, 0xf7, 0xff, 0xf9, 0xf1, 0xf8,
0x00, 0x0e, 0x38, 0x73, 0xe1, 0xfc, 0x7f, 0xfc, 0x1f, 0x01, 0xff, 0xff, 0xc0, 0xf9, 0xf0, 0xf8,
0x00, 0x06, 0x78, 0x7b, 0xe1, 0xfc, 0x7f, 0xfc, 0x1f, 0x01, 0xff, 0xff, 0xc0, 0x7d, 0xf0, 0xfc,
0x00, 0x04, 0xf0, 0x3f, 0xe0, 0xfc, 0x7f, 0xfc, 0x1f, 0x01, 0xff, 0xff, 0x80, 0x7d, 0xf0, 0x7c,
0x00, 0x01, 0xf0, 0x3f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x07, 0xe0, 0x1f, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0f, 0xc0, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x3f, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00,
0x00, 0xfe, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00,
0x03, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0,
0x07, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0,
0x03, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0,
0x00, 0xfe, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00,
0x00, 0x3f, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0f, 0xc0, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x07, 0xe0, 0x1f, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0xf0, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xf0, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x78, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x38, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3c, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x1c, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x1f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x03, 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, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
void setup() {
Serial.begin(115200);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT);
}
// Clear the buffer
display.clearDisplay();
// Show the display buffer on the screen. You MUST call display() after
// drawing commands to make them visible on screen!
display.display();
// display.display() is NOT necessary after every single drawing command,
// unless that's what you want...rather, you can batch up a bunch of
// drawing operations and then update the screen all at once by calling
// display.display(). These examples demonstrate both approaches...
STARTUP();
BALCOUNT();
POWEROFF();
ADDOFF();
TAKEOFF();
}
bool POWER = false;
bool PBPREVIOUS = LOW;
int BELTSPEED = 100;
int BBOUNCE = 300;
bool TBPREV = LOW;
bool ABPREV = LOW;
void loop() {
if ( digitalRead(3) == HIGH && PBPREVIOUS == LOW){
if (POWER == false){
POWERON();
POWER = true;
}
else{
POWEROFF();
POWER = false;
}
delay(BBOUNCE);
}
PBPREVIOUS = digitalRead(3);
if (digitalRead(2)==HIGH && TBPREV == LOW){
TAKEON();
delay(BBOUNCE);
TAKEOFF();
}
TBPREV = digitalRead(2);
if (digitalRead(4)==HIGH && ABPREV == LOW){
ADDON();
delay(BBOUNCE);
ADDOFF();
}
ABPREV = digitalRead(4);
}
void STARTUP(void) {
display.clearDisplay();
display.drawBitmap(
(display.width() - LOGO_WIDTH ) / 2,
(display.height() - LOGO_HEIGHT) / 2,
logo_bmp, LOGO_WIDTH, LOGO_HEIGHT, 1);
display.setTextColor(WHITE, BLACK);
display.setTextWrap(0);
display.setCursor(60, 50);
display.println("ENTERPRISES");
display.display();
delay(2000);
}
void BALCOUNT() {
int y = 0;
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.setFont(NULL);
display.setCursor(0, y+6);
display.fillRect(8, y+4, 111, 10, 1);
display.setTextColor(BLACK, WHITE);
display.setTextWrap(0);
display.setCursor(10, y+6);
display.println("DOLLARS PER MINUTE");
display.setTextWrap(0);
display.setCursor(64, 14);
display.println("");
display.drawRoundRect(8, y+4, 111, 20, 3, 1);
display.setCursor(0, y+15);
display.setTextColor(WHITE);
display.setTextWrap(0);
display.setCursor(55, y+15);
display.println("$24");
display.display();
}
void POWEROFF() {
display.fillCircle(64, 40, 10, 0);
display.drawCircle(64, 40, 10, 1);
display.drawCircle(64, 40, 5, 1);
display.fillRect(62, 35, 5, 1, 0);
display.fillRect(64, 34, 1, 6, 1);
display.display();
}
void POWERON() {
display.drawCircle(64, 40, 10, 1);
display.fillCircle(64, 40, 10, 1);
display.drawCircle(64, 40, 5, 0);
display.fillRect(62, 35, 5, 1, 1);
display.fillRect(64, 34, 1, 6, 0);
display.display();
}
void ADDOFF() {
display.fillCircle(99, 40, 10, 0);
display.drawCircle(99, 40, 10, 1);
display.drawLine(93, 40, 105, 40, 1);
display.drawLine(99, 34, 99, 46, 1);
display.display();
}
void ADDON() {
display.fillCircle(99, 40, 10, 1);
display.drawLine(93, 40, 105, 40, 0);
display.drawLine(99, 34, 99, 46, 0);
display.display();
}
void TAKEOFF() {
display.fillCircle(29, 40, 10, 0);
display.drawCircle(29, 40, 10, 1);
display.drawLine(23, 40, 35, 40, 1);
display.display();
}
void TAKEON() {
display.fillCircle(29, 40, 10, 1);
display.drawLine(23, 40, 35, 40, 0);
display.display();
}