Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unsigned long temp;
- //WITH Test1ISTOR ,
- //pinMode(buttonPin, INPUT);
- //digitalWrite(buttonPin, HIGH); //CLOSE
- //digitalWrite(buttonPin, LOW); //OPEN
- //
- //WITHOUT Test1ISTOR
- //pinMode(buttonPin, INPUT_PULLUP);
- //digitalWrite(buttonPin, LOW); //CLOSE
- //digitalWrite(buttonPin, HIGH); //OPEN
- unsigned long previousMillis = 0; // will store last time LED was updated
- const long interval = 10000;
- long lcdCoin = 0;
- unsigned long previousResetMillis = 0;
- bool resetNow = false;
- unsigned long startTime = 0;
- unsigned long checkTime = 0;
- bool displayCoinCount = false;
- int dummyCounter = 0;
- unsigned long debounceDelay = 10;
- bool activateButton = false;
- bool editMode = false;
- bool displayMainMessage = true;
- bool displayVouch = false;
- #define buttonPinTest1 3
- int buttonStateTest1;
- int lastButtonStateTest1 = LOW;
- unsigned long lastDebounceTimeTest1 = 0;
- #define buttonPinTest2 4
- int buttonStateTest2;
- int lastButtonStateTest2 = LOW;
- unsigned long lastDebounceTimeTest2 = 0;
- #define buttonPinTest3 7
- int buttonStateTest3;
- int lastButtonStateTest3 = LOW;
- unsigned long lastDebounceTimeTest3 = 0;
- long userCode;
- int perPisoMin = 5; //ILANG MINUTES PER PISO, EDITABLE BY FUCKING EEPROM
- long computation = perPisoMin * 60L;
- long hourPromo = 3600UL;
- //promo prices
- int promo1 = 10;
- int promo2 = 15;
- int promo3 = 20;
- int promo4 = 30;
- int promo5 = 150;
- //promo hour
- int promoOne = 1;
- int promoTwo = 6;
- int promoThree = 12;
- int promoFour = 24;
- int promoFive = 168;
- long promoComp;
- long promoHour = 3600UL;
- unsigned long promoTime;
- int counterMap = 0;
- #include <LiquidCrystal_I2C.h> //library
- #include <Wire.h>
- #define BACKLIGHT_PIN 13 //backlight pin
- LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
- int counter = 0;
- int counterChange = -1;
- #define coinSlotPin 2
- int coins = 0;
- int lastCoinCount = 0;
- long promoFinal;
- long inBet = 0;
- void coinInserted()
- {
- coins++;
- if (coins < promo1)
- {
- promoFinal = computation * coins;
- }
- else if (coins >= promo1 && coins < promo2)
- {
- promoTime = promoOne * promoHour;
- promoComp = coins - promo1;
- inBet = promoComp * computation;
- promoFinal = inBet + promoTime;
- }
- else if (coins >= promo2 && coins < promo3)
- {
- promoTime = promoTwo * promoHour;
- promoComp = coins - promo2;
- inBet = promoComp * computation;
- promoFinal = inBet + promoTime;
- }
- else if (coins >= promo3 && coins < promo4)
- {
- promoTime = promoThree * promoHour;
- promoComp = coins - promo3;
- inBet = promoComp * computation;
- promoFinal = inBet + promoTime;
- }
- else if (coins >= promo4 && coins < promo5)
- {
- //promo4 = 30;
- //60 modulo
- promoTime = promoFour * promoHour;
- promoComp = coins - promo4;
- inBet = promoComp * computation;
- promoFinal = inBet + promoTime;
- }
- else if (coins >= promo5)
- { promoTime = promoFive * promoHour;
- promoComp = coins - promo5;
- inBet = promoComp * computation;
- promoFinal = inBet + promoTime;
- }
- Serial.println(promoFinal);
- }
- void setup()
- {
- pinMode(coinSlotPin, INPUT);
- attachInterrupt(0, coinInserted, RISING);
- //coins = 60;
- Serial.begin(9600);
- pinMode(buttonPinTest1, INPUT);
- pinMode(buttonPinTest2, INPUT);
- pinMode(buttonPinTest3, INPUT);
- lcd.begin(16, 2); //Init with pin default ESP8266 or ARDUINO
- }
- void loop() {
- readBtnTest1();
- readBtnTest2();
- readBtnTest3();
- //Serial.println(counter);
- editModeCheck();
- displayCheck();
- noNegative();
- // Serial.println(lcdCoin);
- displayCoin();
- displayVoucher();
- userCode = random(10000, 99999);
- //Serial.println(promoFinal);
- }
- void readBtnTest1() {
- int reading = digitalRead(buttonPinTest1);
- if (reading != lastButtonStateTest1) {
- lastDebounceTimeTest1 = millis();
- }
- if ((millis() - lastDebounceTimeTest1) > debounceDelay) {
- if (reading != buttonStateTest1) {
- buttonStateTest1 = reading;
- if (buttonStateTest1 == HIGH)
- {
- counter++;
- }
- }
- }
- lastButtonStateTest1 = reading;
- }
- void readBtnTest2() {
- int reading = digitalRead(buttonPinTest2);
- if (reading != lastButtonStateTest2) {
- lastDebounceTimeTest2 = millis();
- }
- if ((millis() - lastDebounceTimeTest2) > debounceDelay) {
- if (reading != buttonStateTest2) {
- buttonStateTest2 = reading;
- if (buttonStateTest2 == HIGH)
- {
- counter--;
- }
- }
- }
- lastButtonStateTest2 = reading;
- }
- void readBtnTest3() {
- int reading = digitalRead(buttonPinTest3);
- if (reading != lastButtonStateTest3) {
- lastDebounceTimeTest3 = millis();
- }
- if ((millis() - lastDebounceTimeTest3) > debounceDelay) {
- if (reading != buttonStateTest3) {
- buttonStateTest3 = reading;
- if (buttonStateTest3 == HIGH)
- {
- counterChange++;
- Serial.println(counterChange);
- }
- }
- }
- lastButtonStateTest3 = reading;
- }
- void booleanCheck()
- {
- if (counter == 5)
- {
- activateButton = true;
- }
- }
- void editModeCheck()
- {
- if (counterChange > 0 && displayMainMessage == true)
- {
- counterChange = 0;
- }
- if (counter == 5 && activateButton == false && dummyCounter == 0)
- {
- booleanCheck();
- dummyCounter++;
- }
- else if (activateButton == true)
- {
- displayMainMessage = false;
- counter = 0;
- activateButton = false;
- editMode = true;
- }
- if (editMode == true)
- {
- displayEditMode();
- if (counterChange == 1)
- {
- displayVoucher();
- displayVouch = true;
- editMode = false;
- resetCountStart();
- }
- }
- if (coins > 0)
- {
- userCode = random(10000, 99999);
- displayMainMessage = false;
- displayCoinCount = true; //map
- if (counterChange == 1)
- {
- displayVouch = true;
- displayVoucher();
- displayVouch = true;
- displayCoinCount = false;
- resetCountStart();
- lcdCoin = coins;
- coins = 0;
- }
- }
- if (displayVouch == true)
- {
- counterMap = 1;
- displayVouch = false;
- Serial.println("Wait reset");
- }
- if (counterMap == 1 && displayVouch == false)
- {
- resetAfter(6);
- if (resetNow == true && displayCoinCount == false || counterChange == 2)
- {
- Serial.println("TITE");
- Serial.println("Reset ");
- resetVariable();
- counterMap = 0;
- //map666
- }
- }
- }
- void resetAfter(int sec) {
- unsigned long currentResetMillis = millis();
- sec *= 1000;
- if (currentResetMillis - previousResetMillis >= sec && !resetNow) {
- previousResetMillis = currentResetMillis;
- resetNow = true;
- //Serial.println("Reset Now");
- }
- }
- void resetCountStart() {
- unsigned long currentResetMillis = millis();
- previousResetMillis = currentResetMillis;
- resetNow = false;
- }
- void displayCheck()
- {
- if (displayMainMessage == true)
- {
- lcdCoin = 0;
- editMode = false;
- lcd.setCursor(0, 0);
- lcd.print(F("this is main msg "));
- lcd.setCursor(0, 1);
- lcd.print(F("this is main msg "));
- }
- }
- void displayEditMode()
- {
- if (editMode == true)
- {
- lcd.setCursor(0, 0);
- lcd.print(F("EDIT MODE "));
- lcd.setCursor(0, 1);
- lcd.print(counter);
- lcd.print(F(" "));
- }
- }
- void noNegative()
- {
- if (counter < 0)
- {
- counter = 0;
- }
- }
- void displayVoucher()
- {
- if (displayVouch)
- {
- lcd.setCursor(0, 0);
- lcd.print(userCode);
- lcd.print(" CODE");
- lcd.setCursor(0, 1);
- lcd.print(promoFinal);
- format(promoFinal);
- }
- }
- void resetVariable()
- {
- counterChange = 0;
- displayVouch = false;
- editMode = false;
- displayMainMessage = true;
- counter = 0;
- dummyCounter = 0;
- displayCoinCount = false;
- coins = 0;
- }
- void displayCoin()
- {
- if (displayCoinCount)
- {
- lcd.setCursor(0, 0);
- lcd.print(coins);
- lcd.print(" ");
- lcdCoin = coins;
- lcd.setCursor(4, 0);
- // checkPromo();
- lcd.print(promoFinal);
- temp = promoFinal;
- format(promoFinal);
- }
- }
- void checkPromo()
- {
- // if (lcdCoin < promo1)
- // {
- // promoFinal = computation * lcdCoin;
- // }
- // else if (lcdCoin >= promo1 && lcdCoin < promo2)
- // {
- // promoTime = promoOne * promoHour;
- // promoComp = lcdCoin % promo1; //40 yung coin count, pumasok sa coin count na 30 tas may sampong piso na per rate na in between
- // inBetween = promoComp * computation; //REMAINDER MULTIPLY MO SA PRESYO PER PISO TAS ADD MO YUNG REMAINDER
- // promoFinal = inBetween + promoTime;
- // }
- // else if (lcdCoin >= promo2 && lcdCoin < promo3)
- // {
- // promoTime = promoTwo * promoHour;
- // promoComp = lcdCoin % promo2; //40 yung coin count, pumasok sa coin count na 30 tas may sampong piso na per rate na in between
- // inBetween = promoComp * computation; //REMAINDER MULTIPLY MO SA PRESYO PER PISO TAS ADD MO YUNG REMAINDER
- // promoFinal = inBetween + promoTime;
- //
- // }
- // else if (lcdCoin >= promo3 && lcdCoin < promo4)
- // {
- // promoComp = lcdCoin % promo3; //40 yung coin count, pumasok sa coin count na 30 tas may sampong piso na per rate na in between
- // inBetween = promoComp * computation; //REMAINDER MULTIPLY MO SA PRESYO PER PISO TAS ADD MO YUNG REMAINDER
- // promoTime = promoThree * promoHour;
- // promoFinal = inBetween + promoTime; //FINAL SHIT
- // }
- // else if (lcdCoin == promo4)
- // {
- // promoTime = promoFour * promoHour;
- // promoFinal = inBetween + promoTime;
- // }
- // else if (lcdCoin >= promo4 && lcdCoin < promo5)
- // {
- // promoComp = lcdCoin % promo4;
- // inBetween = promoComp * computation;
- // promoTime = promoFour * promoHour;
- // promoFinal = inBetween + promoTime;
- // }
- // else if (lcdCoin >= promo5)
- // {
- // promoComp = lcdCoin % promo5; //40 yung coin count, pumasok sa coin count na 30 tas may sampong piso na per rate na in between
- // inBetween = promoComp * computation; //REMAINDER MULTIPLY MO SA PRESYO PER PISO TAS ADD MO YUNG REMAINDER
- // promoTime = promoFive * promoHour;
- // promoFinal = inBetween + promoTime; //FINAL SHIT
- // }
- }
- void format( long seconds) {
- long W = seconds / 604800;
- seconds = seconds % 604800;
- long D = seconds / 86400;
- seconds = seconds % 86400;
- long H = seconds / 3600;
- seconds = seconds % 3600;
- long M = seconds / 60;
- long S = seconds % 60;
- lcd.setCursor(0, 1);
- lcd.print(W);
- lcd.print("W");
- lcd.print("-");
- lcd.print(D);
- lcd.print("D");
- lcd.print("-");
- lcd.print(H);
- lcd.print("H");
- lcd.print(":");
- lcd.print(M);
- lcd.print("M");
- lcd.print(" ");
- }
Add Comment
Please, Sign In to add comment