naivxnaivet

JHUN (TRANSLATE TO NODEMCU AND EDIT PROMO)

Jun 8th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.70 KB | None | 0 0
  1. unsigned long temp;
  2.  
  3. //WITH Test1ISTOR ,
  4. //pinMode(buttonPin, INPUT);
  5. //digitalWrite(buttonPin, HIGH); //CLOSE
  6. //digitalWrite(buttonPin, LOW); //OPEN
  7. //
  8. //WITHOUT Test1ISTOR
  9. //pinMode(buttonPin, INPUT_PULLUP);
  10. //digitalWrite(buttonPin, LOW); //CLOSE
  11. //digitalWrite(buttonPin, HIGH); //OPEN
  12. unsigned long previousMillis = 0; // will store last time LED was updated
  13. const long interval = 10000;
  14. long lcdCoin = 0;
  15. unsigned long previousResetMillis = 0;
  16. bool resetNow = false;
  17.  
  18. unsigned long startTime = 0;
  19. unsigned long checkTime = 0;
  20.  
  21. bool displayCoinCount = false;
  22.  
  23. int dummyCounter = 0;
  24.  
  25. unsigned long debounceDelay = 10;
  26.  
  27. bool activateButton = false;
  28. bool editMode = false;
  29. bool displayMainMessage = true;
  30. bool displayVouch = false;
  31.  
  32. #define buttonPinTest1 3
  33. int buttonStateTest1;
  34. int lastButtonStateTest1 = LOW;
  35. unsigned long lastDebounceTimeTest1 = 0;
  36.  
  37. #define buttonPinTest2 4
  38. int buttonStateTest2;
  39. int lastButtonStateTest2 = LOW;
  40. unsigned long lastDebounceTimeTest2 = 0;
  41.  
  42.  
  43. #define buttonPinTest3 7
  44. int buttonStateTest3;
  45. int lastButtonStateTest3 = LOW;
  46. unsigned long lastDebounceTimeTest3 = 0;
  47.  
  48. long userCode;
  49.  
  50. int perPisoMin = 5; //ILANG MINUTES PER PISO, EDITABLE BY FUCKING EEPROM
  51. long computation = perPisoMin * 60L;
  52. long hourPromo = 3600UL;
  53.  
  54. //promo prices
  55. int promo1 = 10;
  56. int promo2 = 15;
  57. int promo3 = 20;
  58. int promo4 = 30;
  59. int promo5 = 150;
  60.  
  61. //promo hour
  62. int promoOne = 1;
  63. int promoTwo = 6;
  64. int promoThree = 12;
  65. int promoFour = 24;
  66. int promoFive = 168;
  67. long promoComp;
  68. long promoHour = 3600UL;
  69.  
  70. unsigned long promoTime;
  71.  
  72.  
  73. int counterMap = 0;
  74.  
  75. #include <LiquidCrystal_I2C.h> //library
  76. #include <Wire.h>
  77. #define BACKLIGHT_PIN 13 //backlight pin
  78.  
  79. LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
  80.  
  81. int counter = 0;
  82. int counterChange = -1;
  83.  
  84. #define coinSlotPin 2
  85.  
  86. int coins = 0;
  87. int lastCoinCount = 0;
  88. long promoFinal;
  89. long inBet = 0;
  90. void coinInserted()
  91. {
  92. coins++;
  93.  
  94. if (coins < promo1)
  95. {
  96. promoFinal = computation * coins;
  97. }
  98. else if (coins >= promo1 && coins < promo2)
  99. {
  100. promoTime = promoOne * promoHour;
  101. promoComp = coins - promo1;
  102. inBet = promoComp * computation;
  103. promoFinal = inBet + promoTime;
  104. }
  105. else if (coins >= promo2 && coins < promo3)
  106. {
  107. promoTime = promoTwo * promoHour;
  108. promoComp = coins - promo2;
  109. inBet = promoComp * computation;
  110. promoFinal = inBet + promoTime;
  111. }
  112. else if (coins >= promo3 && coins < promo4)
  113. {
  114. promoTime = promoThree * promoHour;
  115. promoComp = coins - promo3;
  116. inBet = promoComp * computation;
  117. promoFinal = inBet + promoTime;
  118.  
  119. }
  120. else if (coins >= promo4 && coins < promo5)
  121. {
  122. //promo4 = 30;
  123.  
  124. //60 modulo
  125.  
  126. promoTime = promoFour * promoHour;
  127. promoComp = coins - promo4;
  128. inBet = promoComp * computation;
  129. promoFinal = inBet + promoTime;
  130. }
  131. else if (coins >= promo5)
  132. { promoTime = promoFive * promoHour;
  133. promoComp = coins - promo5;
  134. inBet = promoComp * computation;
  135. promoFinal = inBet + promoTime;
  136. }
  137. Serial.println(promoFinal);
  138.  
  139. }
  140. void setup()
  141. {
  142. pinMode(coinSlotPin, INPUT);
  143. attachInterrupt(0, coinInserted, RISING);
  144. //coins = 60;
  145. Serial.begin(9600);
  146. pinMode(buttonPinTest1, INPUT);
  147. pinMode(buttonPinTest2, INPUT);
  148. pinMode(buttonPinTest3, INPUT);
  149. lcd.begin(16, 2); //Init with pin default ESP8266 or ARDUINO
  150. }
  151.  
  152.  
  153. void loop() {
  154. readBtnTest1();
  155. readBtnTest2();
  156. readBtnTest3();
  157. //Serial.println(counter);
  158. editModeCheck();
  159. displayCheck();
  160. noNegative();
  161. // Serial.println(lcdCoin);
  162. displayCoin();
  163. displayVoucher();
  164. userCode = random(10000, 99999);
  165. //Serial.println(promoFinal);
  166. }
  167.  
  168. void readBtnTest1() {
  169. int reading = digitalRead(buttonPinTest1);
  170. if (reading != lastButtonStateTest1) {
  171. lastDebounceTimeTest1 = millis();
  172. }
  173. if ((millis() - lastDebounceTimeTest1) > debounceDelay) {
  174. if (reading != buttonStateTest1) {
  175. buttonStateTest1 = reading;
  176. if (buttonStateTest1 == HIGH)
  177. {
  178. counter++;
  179. }
  180. }
  181. }
  182. lastButtonStateTest1 = reading;
  183. }
  184.  
  185. void readBtnTest2() {
  186. int reading = digitalRead(buttonPinTest2);
  187. if (reading != lastButtonStateTest2) {
  188. lastDebounceTimeTest2 = millis();
  189. }
  190. if ((millis() - lastDebounceTimeTest2) > debounceDelay) {
  191. if (reading != buttonStateTest2) {
  192. buttonStateTest2 = reading;
  193. if (buttonStateTest2 == HIGH)
  194. {
  195. counter--;
  196. }
  197. }
  198. }
  199. lastButtonStateTest2 = reading;
  200. }
  201.  
  202.  
  203. void readBtnTest3() {
  204. int reading = digitalRead(buttonPinTest3);
  205. if (reading != lastButtonStateTest3) {
  206. lastDebounceTimeTest3 = millis();
  207. }
  208. if ((millis() - lastDebounceTimeTest3) > debounceDelay) {
  209. if (reading != buttonStateTest3) {
  210. buttonStateTest3 = reading;
  211. if (buttonStateTest3 == HIGH)
  212. {
  213. counterChange++;
  214. Serial.println(counterChange);
  215. }
  216. }
  217. }
  218. lastButtonStateTest3 = reading;
  219. }
  220.  
  221. void booleanCheck()
  222. {
  223. if (counter == 5)
  224. {
  225. activateButton = true;
  226. }
  227. }
  228.  
  229. void editModeCheck()
  230. {
  231. if (counterChange > 0 && displayMainMessage == true)
  232. {
  233. counterChange = 0;
  234. }
  235.  
  236.  
  237.  
  238.  
  239. if (counter == 5 && activateButton == false && dummyCounter == 0)
  240. {
  241. booleanCheck();
  242. dummyCounter++;
  243. }
  244.  
  245. else if (activateButton == true)
  246. {
  247. displayMainMessage = false;
  248. counter = 0;
  249. activateButton = false;
  250. editMode = true;
  251. }
  252.  
  253. if (editMode == true)
  254. {
  255. displayEditMode();
  256. if (counterChange == 1)
  257. {
  258. displayVoucher();
  259. displayVouch = true;
  260. editMode = false;
  261. resetCountStart();
  262. }
  263.  
  264. }
  265. if (coins > 0)
  266. {
  267. userCode = random(10000, 99999);
  268.  
  269. displayMainMessage = false;
  270. displayCoinCount = true; //map
  271. if (counterChange == 1)
  272. {
  273. displayVouch = true;
  274. displayVoucher();
  275. displayVouch = true;
  276. displayCoinCount = false;
  277. resetCountStart();
  278. lcdCoin = coins;
  279. coins = 0;
  280. }
  281.  
  282. }
  283.  
  284. if (displayVouch == true)
  285. {
  286. counterMap = 1;
  287. displayVouch = false;
  288. Serial.println("Wait reset");
  289. }
  290. if (counterMap == 1 && displayVouch == false)
  291. {
  292. resetAfter(6);
  293. if (resetNow == true && displayCoinCount == false || counterChange == 2)
  294. {
  295. Serial.println("TITE");
  296. Serial.println("Reset ");
  297. resetVariable();
  298. counterMap = 0;
  299. //map666
  300. }
  301. }
  302. }
  303.  
  304.  
  305. void resetAfter(int sec) {
  306. unsigned long currentResetMillis = millis();
  307. sec *= 1000;
  308. if (currentResetMillis - previousResetMillis >= sec && !resetNow) {
  309. previousResetMillis = currentResetMillis;
  310. resetNow = true;
  311. //Serial.println("Reset Now");
  312. }
  313. }
  314.  
  315. void resetCountStart() {
  316. unsigned long currentResetMillis = millis();
  317. previousResetMillis = currentResetMillis;
  318. resetNow = false;
  319. }
  320.  
  321.  
  322.  
  323.  
  324. void displayCheck()
  325. {
  326. if (displayMainMessage == true)
  327. {
  328. lcdCoin = 0;
  329. editMode = false;
  330.  
  331. lcd.setCursor(0, 0);
  332. lcd.print(F("this is main msg "));
  333. lcd.setCursor(0, 1);
  334. lcd.print(F("this is main msg "));
  335. }
  336. }
  337.  
  338. void displayEditMode()
  339. {
  340. if (editMode == true)
  341. {
  342. lcd.setCursor(0, 0);
  343. lcd.print(F("EDIT MODE "));
  344. lcd.setCursor(0, 1);
  345. lcd.print(counter);
  346. lcd.print(F(" "));
  347. }
  348. }
  349.  
  350. void noNegative()
  351. {
  352. if (counter < 0)
  353. {
  354. counter = 0;
  355. }
  356. }
  357.  
  358. void displayVoucher()
  359. {
  360. if (displayVouch)
  361. {
  362.  
  363. lcd.setCursor(0, 0);
  364. lcd.print(userCode);
  365. lcd.print(" CODE");
  366. lcd.setCursor(0, 1);
  367. lcd.print(promoFinal);
  368. format(promoFinal);
  369. }
  370. }
  371.  
  372. void resetVariable()
  373. {
  374. counterChange = 0;
  375. displayVouch = false;
  376. editMode = false;
  377. displayMainMessage = true;
  378. counter = 0;
  379. dummyCounter = 0;
  380. displayCoinCount = false;
  381. coins = 0;
  382. }
  383.  
  384. void displayCoin()
  385. {
  386. if (displayCoinCount)
  387. {
  388. lcd.setCursor(0, 0);
  389. lcd.print(coins);
  390. lcd.print(" ");
  391.  
  392. lcdCoin = coins;
  393. lcd.setCursor(4, 0);
  394. // checkPromo();
  395.  
  396. lcd.print(promoFinal);
  397. temp = promoFinal;
  398.  
  399. format(promoFinal);
  400.  
  401. }
  402. }
  403.  
  404.  
  405. void checkPromo()
  406. {
  407. // if (lcdCoin < promo1)
  408. // {
  409. // promoFinal = computation * lcdCoin;
  410. // }
  411. // else if (lcdCoin >= promo1 && lcdCoin < promo2)
  412. // {
  413. // promoTime = promoOne * promoHour;
  414. // promoComp = lcdCoin % promo1; //40 yung coin count, pumasok sa coin count na 30 tas may sampong piso na per rate na in between
  415. // inBetween = promoComp * computation; //REMAINDER MULTIPLY MO SA PRESYO PER PISO TAS ADD MO YUNG REMAINDER
  416. // promoFinal = inBetween + promoTime;
  417. // }
  418. // else if (lcdCoin >= promo2 && lcdCoin < promo3)
  419. // {
  420. // promoTime = promoTwo * promoHour;
  421. // promoComp = lcdCoin % promo2; //40 yung coin count, pumasok sa coin count na 30 tas may sampong piso na per rate na in between
  422. // inBetween = promoComp * computation; //REMAINDER MULTIPLY MO SA PRESYO PER PISO TAS ADD MO YUNG REMAINDER
  423. // promoFinal = inBetween + promoTime;
  424. //
  425. // }
  426. // else if (lcdCoin >= promo3 && lcdCoin < promo4)
  427. // {
  428. // promoComp = lcdCoin % promo3; //40 yung coin count, pumasok sa coin count na 30 tas may sampong piso na per rate na in between
  429. // inBetween = promoComp * computation; //REMAINDER MULTIPLY MO SA PRESYO PER PISO TAS ADD MO YUNG REMAINDER
  430. // promoTime = promoThree * promoHour;
  431. // promoFinal = inBetween + promoTime; //FINAL SHIT
  432. // }
  433. // else if (lcdCoin == promo4)
  434. // {
  435. // promoTime = promoFour * promoHour;
  436. // promoFinal = inBetween + promoTime;
  437. // }
  438. // else if (lcdCoin >= promo4 && lcdCoin < promo5)
  439. // {
  440. // promoComp = lcdCoin % promo4;
  441. // inBetween = promoComp * computation;
  442. // promoTime = promoFour * promoHour;
  443. // promoFinal = inBetween + promoTime;
  444. // }
  445. // else if (lcdCoin >= promo5)
  446. // {
  447. // promoComp = lcdCoin % promo5; //40 yung coin count, pumasok sa coin count na 30 tas may sampong piso na per rate na in between
  448. // inBetween = promoComp * computation; //REMAINDER MULTIPLY MO SA PRESYO PER PISO TAS ADD MO YUNG REMAINDER
  449. // promoTime = promoFive * promoHour;
  450. // promoFinal = inBetween + promoTime; //FINAL SHIT
  451. // }
  452. }
  453.  
  454.  
  455. void format( long seconds) {
  456. long W = seconds / 604800;
  457. seconds = seconds % 604800;
  458. long D = seconds / 86400;
  459. seconds = seconds % 86400;
  460. long H = seconds / 3600;
  461. seconds = seconds % 3600;
  462. long M = seconds / 60;
  463. long S = seconds % 60;
  464.  
  465. lcd.setCursor(0, 1);
  466. lcd.print(W);
  467. lcd.print("W");
  468. lcd.print("-");
  469. lcd.print(D);
  470. lcd.print("D");
  471. lcd.print("-");
  472. lcd.print(H);
  473. lcd.print("H");
  474. lcd.print(":");
  475. lcd.print(M);
  476. lcd.print("M");
  477. lcd.print(" ");
  478.  
  479. }
Add Comment
Please, Sign In to add comment