#include "U8glib.h"
int led = 5;
int button = 4;
int inputPin = 13;
int motionCounter = 0;
int buyCounter = 0;
int val = 0;
int cr = 0;
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0 | U8G_I2C_OPT_NO_ACK | U8G_I2C_OPT_FAST);
void setup() {
// put your setup code here, to run once:
pinMode(led, OUTPUT);
pinMode(button, INPUT_PULLUP);
pinMode(inputPin, INPUT);
u8g.setFont(u8g_font_tpssb);
u8g.setColorIndex(1);
}
void loop() {
// put your main code here, to run repeatedly:
cr = motionCounter/buyCounter;
String stringOne = "Come: ";
stringOne += motionCounter;
char charBuf[100];
stringOne.toCharArray(charBuf, 100);
String stringTwo = "Bought: ";
stringTwo += buyCounter;
char charBuff[100];
stringTwo.toCharArray(charBuff, 100);
String stringThree = "CR: ";
stringThree += cr;
char charBufff[100];
stringThree.toCharArray(charBufff, 100);
u8g.firstPage();
do {
u8g.drawStr(25, 20, charBuf);
u8g.drawStr(25, 40, charBuff);
u8g.drawStr(25, 60, charBufff);
} while ( u8g.nextPage() );
val = digitalRead(inputPin);
if (val == HIGH) {
digitalWrite(led, HIGH);
motionCounter++;
val = LOW;
delay(5000);
} else {
digitalWrite(led, LOW);
}
boolean buttonIsUp = digitalRead(button);
if (buttonIsUp == false) {
digitalWrite(led, HIGH);
buyCounter++;
buttonIsUp = true;
delay(5000);
} else {
digitalWrite(led, LOW);
}
}