Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //WITH RESISTOR ,
- //pinMode(buttonPin, INPUT);
- //digitalWrite(buttonPin, HIGH); //CLOSE
- //digitalWrite(buttonPin, LOW); //OPEN
- //
- //WITHOUT RESISTOR
- //pinMode(buttonPin, INPUT_PULLUP);
- //digitalWrite(buttonPin, LOW); //CLOSE
- //digitalWrite(buttonPin, HIGH); //OPEN
- //15 promo1
- //20 promo2
- //45 promo3
- //90 promo4
- //110 promo5
- //8 perPisoMin
- #include <LiquidCrystal_I2C.h>
- LiquidCrystal_I2C lcd(0x27, 20, 4);
- bool displayMain = true;
- bool editMode = false;
- unsigned long previousMillis = 0; // will store last time LED was updated
- const long interval = 1000;
- int counter3;
- #include<EEPROM.h>
- #define ep_limit 15
- int epAdd1 = 0;
- int epAdd2 = 30;
- int epAdd3 = 60;
- int epAdd4 = 90;
- int epAdd5 = 120;
- int epAdd6 = 150;
- int epAdd11 = 180;
- int epAdd12 = 210;
- int epAdd13 = 230;
- int epAdd14 = 250;
- int epAdd15 = 2800;
- int coinCount = 0;
- int perPisoMin; //ILANG MINUTES PER PISO, EDITABLE BY FUCKING EEPROM
- int computation = perPisoMin * 60;
- int hourPromo = 3600UL;
- int inBetween;
- //promo prices
- int promo1 = 0;
- int promo2 = 0;
- int promo3 = 0;
- int promo4 = 0;
- int promo5 = 0;
- //promo hour
- int promoOne = 0;
- int promoTwo = 0;
- int promoThree = 0;
- int promoFour = 0;
- int promoFive = 0;
- int promoComp;
- long promoHour = 3600UL;
- unsigned long promoFinal = 0;
- unsigned long promoTime;
- #define buttonPinTes D3
- #define buttonPinRes D7
- #define buttonPinSes A0
- int buttonStateRes;
- int buttonStateTes;
- int buttonStateSes;
- int lastButtonStateTes = LOW;
- int lastButtonStateRes = LOW;
- int lastButtonStateSes = LOW;
- unsigned long lastDebounceTimeRes = 0;
- unsigned long lastDebounceTimeTes = 0;
- unsigned long lastDebounceTimeSes = 0;
- unsigned long debounceDelay = 0;
- bool resSelected = false;
- unsigned int editRates;
- unsigned int counter2;
- #include <ESP8266TelnetClient.h>
- #include <ESP8266WiFi.h>
- #include <ESP8266WiFiMulti.h>
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- IPAddress mikrotikRouterIp (192, 168, 22, 1);
- const char* user = "admin";
- const char* pwd = "Secreto#020202";
- const char* ssid = "MikroTik Wifi";
- const char* password = "Secreto#020202";
- String M_command;
- ESP8266WiFiMulti WiFiMulti;
- WiFiClient client;
- ESP8266telnetClient tc(client);
- int costc = 300; //
- int y = 0;
- int hourr = 0;
- int minn = 0;
- int secc = 0;
- int dayy = 0;
- int temp = 0;
- int startTime = 0;
- int userCode = 0;
- int cantWaitTheCode = 0;
- int checkTime = 0;
- char const *c;
- void ICACHE_RAM_ATTR coinAccept()
- {
- y = 0;
- coinCount++;
- digitalWrite(LED_BUILTIN, LOW);
- }
- void ICACHE_RAM_ATTR buttonPush()
- {
- if (coinCount > 0)
- //if(coinCounnt >= 0)
- {
- cantWaitTheCode = 1;
- }
- //startTime = millis(); // decoy = 1;
- digitalWrite(LED_BUILTIN, LOW);
- }
- void setup()
- {
- lcd.begin();
- lcd.backlight();
- promo1 = ep_read(epAdd1);
- promo2 = ep_read(epAdd2);
- promo3 = ep_read(epAdd3);
- promo4 = ep_read(epAdd4);
- promo5 = ep_read(epAdd5);
- perPisoMin = ep_read(epAdd6);
- promoOne = ep_read(epAdd11);
- promoTwo = ep_read(epAdd12);
- promoThree = ep_read(epAdd13);
- promoFour = ep_read(epAdd14);
- promoFive = ep_read(epAdd15);
- Serial.begin(9600);
- pinMode(buttonPinRes, INPUT_PULLUP);
- pinMode(buttonPinTes, INPUT_PULLUP);
- pinMode(buttonPinSes, INPUT);
- WiFi.mode(WIFI_STA);
- WiFiMulti.addAP(ssid, password);
- attachInterrupt(D5, coinAccept, RISING);
- attachInterrupt(D6, buttonPush, RISING);
- pinMode(D5, INPUT);
- pinMode(D5, INPUT);
- pinMode(LED_BUILTIN, OUTPUT);
- //pinMode(D7, OUTPUT);
- lcd.setCursor(5, 0);
- lcd.print(F("WELCOME TO"));
- lcd.setCursor(0, 1);
- lcd.print(F("JHUNDECK HOTSPOT"));
- digitalWrite(LED_BUILTIN, HIGH);
- delay(1000);
- // Serial.println();
- // Serial.println();
- // Serial.println("Wait for WI-Fi...");
- while (WiFiMulti.run() != WL_CONNECTED)
- {
- // Serial.print(".");
- delay(500);
- }
- // Serial.println("");
- // Serial.println("WiFi connected");
- // Serial.print("IP Address : ");
- // Serial.println(WiFi.localIP());
- // Serial.println("Connecting....");
- tc.setPromptChar('>');
- //manual login pagka may problema
- char key = 0;
- Serial.println("\r\npress enter to begin:");
- do
- {
- key = Serial.read();
- Serial.println(key);
- }
- //automatic login
- while (key <= 0);
- tc.login(mikrotikRouterIp, user, pwd);
- computation = perPisoMin * 60;
- }
- void loop()
- {
- displayMainMessage();
- computation = perPisoMin * 60;
- editPresets();
- readBtnRes();
- readBtnTes();
- readBtnSes();
- digitalWrite(LED_BUILTIN, HIGH);
- if (coinCount > 0)
- {
- displayMain = false;
- check();
- startTime = millis();
- lcd.setCursor(0, 0);
- lcd.print(F("coins : " ));
- lcd.print(coinCount);
- lcd.print(F(" "));
- temp = promoFinal; // ilang minute yung piso
- hourr = floor(temp / 3600);
- temp %= 3600; //temp = temp%3600
- minn = floor (temp / 60);
- secc = temp % 60;
- dayy = floor(hourr / 24);
- lcd.setCursor(0, 1);
- lcd.print(dayy);
- lcd.print(F("D:"));
- lcd.print(hourr);
- lcd.print(F("H:"));
- lcd.print(minn);
- lcd.print(F("M:"));
- lcd.print(secc);
- lcd.print(F("S"));
- checkTime = millis() - startTime;
- if (cantWaitTheCode == 1 && coinCount > 0)
- {
- Serial.println("the value is:");
- Serial.println(coinCount);
- userCode = random(10000, 99999); //ITO YUNG PAPALITAN, LEFT = LOWEST, RIGHT = UPPER
- M_command += "/ip hotspot user add name=";
- M_command += userCode;
- M_command += " limit-uptime=";
- M_command += temp;
- int command_len = M_command.length() + 1;
- char M_F_command[command_len];
- M_command.toCharArray(M_F_command, command_len);
- tc.sendCommand(M_F_command);
- lcd.setCursor(0, 0);
- lcd.print(F(" JHUNDECK WIFI "));
- lcd.setCursor(0, 1);
- lcd.print(F("code : "));
- lcd.print(userCode);
- lcd.print(" ");
- delay(15000);
- M_command = "";
- memset(M_F_command , 0, sizeof(M_F_command ));
- temp = 0;
- coinCount = 0;
- startTime = 0;
- cantWaitTheCode = 0;
- displayMain = true;
- }
- }
- }
- void readBtnRes() {
- int reading = digitalRead(buttonPinRes);
- if (reading != lastButtonStateRes) {
- lastDebounceTimeRes = millis();
- }
- if ((millis() - lastDebounceTimeRes) > debounceDelay) {
- if (reading != buttonStateRes) {
- buttonStateRes = reading;
- if (buttonStateRes == LOW)
- {
- counter2++;
- Serial.println(counter2);
- }
- }
- }
- lastButtonStateRes = reading;
- }
- void readBtnTes()
- {
- int reading = digitalRead(buttonPinTes);
- if (reading != lastButtonStateTes) {
- lastDebounceTimeTes = millis();
- }
- if ((millis() - lastDebounceTimeTes) > debounceDelay) {
- if (reading != buttonStateTes) {
- buttonStateTes = reading;
- if (buttonStateTes == LOW)
- {
- editRates++;
- // '' Serial.println(editRates);
- }
- }
- }
- lastButtonStateTes = reading;
- }
- void readBtnSes() {
- int reading = digitalRead(buttonPinSes);
- if (reading != lastButtonStateSes) {
- lastDebounceTimeRes = millis();
- }
- if ((millis() - lastDebounceTimeSes) > debounceDelay) {
- if (reading != buttonStateSes) {
- buttonStateSes = reading;
- if (buttonStateSes == LOW)
- {
- counter2--;
- Serial.println(counter2);
- }
- }
- }
- lastButtonStateSes = reading;
- }
- void check()
- {
- computation = perPisoMin * 60;
- if (coinCount < promo1)
- {
- promoFinal = coinCount * computation;
- costc = promoFinal;
- }
- else if (coinCount >= promo1 && coinCount < promo2)
- {
- promoTime = promoOne * promoHour;
- promoComp = coinCount % 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;
- costc = promoFinal;
- }
- else if (coinCount >= promo2 && coinCount < promo3)
- {
- promoTime = promoTwo * promoHour;
- promoComp = coinCount % 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;
- costc = promoFinal;
- }
- else if (coinCount >= promo3 && coinCount < promo4)
- {
- promoTime = promoThree * promoHour;
- promoComp = coinCount % 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
- promoFinal = inBetween + promoTime;
- costc = promoFinal;
- }
- else if (coinCount >= promo4 && coinCount < promo5)
- {
- promoComp = coinCount % promo4; //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 = promoFour * promoHour;
- promoFinal = inBetween + promoTime; //FINAL
- costc = promoFinal;
- }
- else if (coinCount >= promo5)
- {
- promoComp = coinCount % 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
- costc = promoFinal;
- }
- }
- int ep_read(int add)
- {
- unsigned int v = 0;
- unsigned int i;
- for (i = 0; i < ep_limit; i++)
- {
- v = v + EEPROM.read(add);
- add++;
- }
- return v;
- }
- void ep_write(int add, const int val)
- {
- int v = val;
- unsigned int i;
- for (i = 0; i < ep_limit; i++) {
- if (255 < v) {
- v = v - 255;
- EEPROM.write(add, 255);
- } else {
- EEPROM.write(add, v);
- v = 0;
- }
- add++;
- }
- }
- void editPresets()
- {
- switch (editRates)
- {
- case 0:
- // Serial.println("WAITING FOR COMMAND");
- editMode = false;
- displayMain = true;
- break;
- case 1:
- editMode = true;
- displayMain = false;
- Serial.println("EDIT PISO PER MINUTE");
- Serial.println(perPisoMin);
- lcd.setCursor(0, 0);
- lcd.print("EDIT MODE ");
- lcd.setCursor(0, 1);
- lcd.print("MINUTE PER PISO");
- lcd.setCursor(0, 2);
- lcd.print(counter2);
- readBtnRes();
- readBtnSes();
- perPisoMin = counter2;
- ep_write(epAdd6, perPisoMin);
- counter3 = 0;
- break;
- case 2:
- editMode = true;
- displayMain = false;
- Serial.println("EDIT PROMO 1 PRICE ");
- Serial.println(promo1);
- lcd.setCursor(0, 0);
- lcd.print("EDIT MODE ");
- lcd.setCursor(0, 1);
- lcd.print("PROMO 1 PRICE");
- lcd.setCursor(0, 2);
- lcd.print(counter2);
- readBtnSes();
- readBtnRes();
- promo1 = counter2;
- ep_write(epAdd1, promo1);
- break;
- case 3:
- Serial.println("EDIT PROMO 1 HOURS");
- Serial.println(promoOne);
- lcd.setCursor(0, 0);
- lcd.print("EDIT MODE ");
- lcd.setCursor(0, 1);
- lcd.print("PROMO 1 HOURS");
- lcd.setCursor(0, 2);
- lcd.print(counter2);
- editMode = true;
- readBtnSes();
- readBtnRes();
- promoOne = counter2;
- ep_write(epAdd11, promoOne);
- break;
- case 4:
- Serial.println("EDIT PROMO 2 PRICE");
- Serial.println(promo2);
- lcd.setCursor(0, 0);
- lcd.print("EDIT MODE ");
- lcd.setCursor(0, 1);
- lcd.print("PROMO 2 PRICE");
- lcd.setCursor(0, 2);
- lcd.print(counter2);
- editMode = true;
- editMode = true;
- readBtnSes();
- readBtnRes();
- promo2 = counter2;
- ep_write(epAdd2, promo2);
- break;
- //
- case 5:
- Serial.println("EDIT PROMO 2 HOURS");
- Serial.println(promoTwo);
- lcd.setCursor(0, 0);
- lcd.print("EDIT MODE");
- lcd.setCursor(0, 1);
- lcd.print("PROMO 1 HOURS");
- lcd.setCursor(0, 2);
- lcd.print(counter2);
- editMode = true;
- editMode = true;
- readBtnSes();
- readBtnRes();
- promoTwo = counter2;
- ep_write(epAdd12, promoTwo);
- break;
- case 6:
- Serial.println("EDIT PROMO 3 PRICE");
- Serial.println(promo3);
- lcd.setCursor(0, 0);
- lcd.print("EDIT MODE");
- lcd.setCursor(0, 1);
- lcd.print("PROMO 3 PRICE");
- lcd.setCursor(0, 2);
- lcd.print(counter2);
- editMode = true;
- editMode = true;
- readBtnSes();
- readBtnRes();
- promo3 = counter2;
- ep_write(epAdd3, promo3);
- break;
- //
- case 7:
- Serial.println("EDIT PROMO 3 HOURS");
- Serial.println(promoThree);
- lcd.setCursor(0, 0);
- lcd.print("EDIT MODE");
- lcd.setCursor(0, 1);
- lcd.print("PROMO 3 HOURS");
- lcd.setCursor(0, 2);
- lcd.print(counter2);
- editMode = true;
- editMode = true;
- readBtnSes();
- readBtnRes();
- promoThree = counter2;
- ep_write(epAdd13, promoThree);
- break;
- case 8:
- Serial.println("EDIT PROMO 4 PRICE");
- Serial.println(promo4);
- lcd.setCursor(0, 0);
- lcd.print("EDIT MODE");
- lcd.setCursor(0, 1);
- lcd.print("PROMO 4 PRICE");
- lcd.setCursor(0, 2);
- lcd.print(counter2);
- editMode = true;
- editMode = true;
- readBtnSes();
- readBtnRes();
- promo4 = counter2;
- ep_write(epAdd4, promo4);
- break;
- case 9:
- Serial.println("EDIT PROMO 4 HOURS");
- Serial.println(promoFour);
- lcd.setCursor(0, 0);
- lcd.print("EDIT MODE");
- lcd.setCursor(0, 1);
- lcd.print("PROMO 4 HOURS");
- lcd.setCursor(0, 2);
- lcd.print(counter2);
- editMode = true;
- editMode = true;
- readBtnSes();
- readBtnRes();
- promoFour = counter2;
- ep_write(epAdd14, promoFour);
- break;
- case 10:
- Serial.println("EDIT PROMO 5 PRICE");
- Serial.println(promo5);
- lcd.setCursor(0, 0);
- lcd.print("EDIT MODE");
- lcd.setCursor(0, 1);
- lcd.print("PROMO PRICE HOURS");
- lcd.setCursor(0, 2);
- lcd.print(counter2);
- editMode = true;
- editMode = true;
- readBtnSes();
- readBtnRes();
- promo5 = counter2;
- ep_write(epAdd5, promo5);
- break;
- case 11:
- Serial.println("EDIT PROMO 5 HOURS");
- lcd.setCursor(0, 0);
- lcd.print("EDIT MODE");
- lcd.setCursor(0, 1);
- lcd.print("PROMO 5 HOURS");
- lcd.setCursor(0, 2);
- lcd.print(counter2);
- editMode = true;
- Serial.println(promoFive);
- editMode = true;
- readBtnSes();
- readBtnRes();
- promoFive = counter2;
- ep_write(epAdd15, promoFive);
- break;
- case 12:
- Serial.println("SAVED");
- lcd.print("Saved");
- delay(2000);
- lcd.clear();
- editRates = 0;
- break;
- }
- }
- void displayMainMessage()
- {
- if (displayMain == true)
- {
- lcd.setCursor(0, 0);
- lcd.print(F(" JHUNDECK WIFI "));
- lcd.setCursor(0, 1);
- lcd.print(F("Pls. Insert Coin/s"));
- lcd.setCursor(0, 2);
- lcd.print(coinCount);
- }
- }
Add Comment
Please, Sign In to add comment