Skip to content

Instantly share code, notes, and snippets.

@RZRZR
Last active June 6, 2016 08:59
Show Gist options
  • Save RZRZR/8a368f46fa03dc3d5b8c4fb27736e3d5 to your computer and use it in GitHub Desktop.
Save RZRZR/8a368f46fa03dc3d5b8c4fb27736e3d5 to your computer and use it in GitHub Desktop.
#include <SPI.h>
const int relayPin = D3;
const int btnPlus = D8;
const int btnMinus = D7;
const int btnBack = D6;
const int btnEnter = D5;
float time = 5.00;
int roundTime = 0;
int plusState = 0;
int minusState = 0;
int backState = 0;
int enterState = 0;
void setup() {
Serial.begin(115200);
pinMode(btnPlus, OUTPUT);
pinMode(btnMinus, OUTPUT);
pinMode(btnBack, OUTPUT);
pinMode(btnEnter, OUTPUT);
pinMode(relayPin, OUTPUT);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 64x48)
// init done
// Show image buffer on the display hardware.
// internally, this will display the splashscreen.
display.display();
delay(2000);
// Clear the buffer.
display.clearDisplay();
}
void loop() {
// text display tests
digitalWrite(relayPin, LOW);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println("Inverter");
display.println("time:");
display.setTextSize(2);
roundTime = round(time);
display.print(" ");
display.println(roundTime);
display.println(" mins");
display.display();
delay(100);
display.clearDisplay();
plusState = digitalRead(btnPlus);
minusState = digitalRead(btnMinus);
backState = digitalRead(btnBack);
enterState = digitalRead(btnEnter);
if (plusState == HIGH){time = time + 1;}
if (minusState == HIGH){if (time == 0) {} else {time = time - 1;} }
if (enterState == HIGH){inverter();}
}
void inverter(void) {
while(time > 0) {
digitalWrite(relayPin, HIGH);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(BLACK, WHITE); // 'inverted' text
display.setCursor(0,0);
display.println("Inverter ");
display.println("time left:");
display.setTextSize(2);
display.print(" ");
roundTime = round(time);
display.print(roundTime);
if (roundTime < 100) { display.print(" ");}
if (roundTime < 10) { display.print(" ");}
display.println(" mins ");
display.display();
delay(1000);
time = time - 0.016;
backState = digitalRead(btnBack);
if (backState == HIGH) {
time = 5;
digitalWrite(relayPin, LOW);
break; }
}
digitalWrite(relayPin, LOW);
time = 0;
finished();
}
void finished(void) {
while (1 == 1) {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(8,20);
display.println("TIMES UP");
display.display();
backState = digitalRead(btnBack);
delay(100);
if (backState == HIGH) {
break; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment