ApelPro

kávéfőző_statem

Apr 22nd, 2021
820
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <LiquidCrystal.h>
  2. #include <Adafruit_NeoPixel.h>
  3.  
  4. const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
  5. LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
  6.  
  7. #define LED_PIN   10
  8. #define LED_COUNT 12
  9.  
  10. Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
  11.  
  12.  
  13. int Credit = 0;
  14.  
  15. typedef enum{
  16.   PENZBEDOBAS = 0,
  17.   VALASZTAS,
  18.   KIADAS,
  19.   PENZVISSZAADAS,
  20.   VARAKOZAS,
  21.   HITELVIZSGALAT
  22. } State;
  23.  
  24. State currState = PENZBEDOBAS;
  25.  
  26. typedef struct{
  27.   int Price;
  28.   char Name[16];
  29. }product_t;
  30.  
  31. product_t products[3] = {
  32.   {80,"Cola"},
  33.   {100, "Fanta"},
  34.   {120, "Tea"}
  35. };
  36.  
  37. int currProduct = 0;
  38.  
  39. void penzBedobas()
  40. {
  41.     lcd.clear();
  42.     lcd.print("Dobja be a penzt");
  43.     delay(1000);
  44.     currState = VARAKOZAS;
  45. }
  46. void varakozas()
  47. {
  48.     if(!digitalRead(8))
  49.     {
  50.         Credit += 20;
  51.     }
  52.     if(!digitalRead(9))
  53.     {
  54.         currProduct = (currProduct + 1) % (sizeof(products) / sizeof(product_t));  
  55.         lcd.clear();
  56.         lcd.print(products[currProduct].Name);
  57.         lcd.setCursor(0,1);      
  58.         lcd.print(products[currProduct].Price);
  59.         lcd.print(" Ft");
  60.         delay(2000);      
  61.     }
  62.  
  63.     if(!digitalRead(7))
  64.     {
  65.       currState = HITELVIZSGALAT;
  66.       return;
  67.     }
  68.     lcd.clear();
  69.     lcd.print("Hitel:");
  70.     lcd.setCursor(0,1);
  71.     lcd.print(Credit);
  72.     lcd.print(" Ft");
  73.     currState = VARAKOZAS;
  74.  
  75. }
  76.  
  77. void hitelVizsgalat()
  78. {
  79.     if(Credit >= products[currProduct].Price)
  80.       currState = KIADAS;
  81.     else
  82.       currState = VARAKOZAS;
  83. }
  84.  
  85. void kiadas()
  86. {
  87.     strip.setPixelColor(0, 0, 255, 0);
  88.     strip.show();
  89.     lcd.clear();
  90.     lcd.print("Keszul:");
  91.     lcd.setCursor(0,1);
  92.     lcd.print(products[currProduct].Name);
  93.     analogWrite(6, 255);
  94.     delay(3000);
  95.     analogWrite(6, 0);
  96.     strip.setPixelColor(0, 0, 0, 0);
  97.     strip.show();
  98.     currState = PENZVISSZAADAS;    
  99. }
  100.  
  101. void penzvisszaadas(){
  102.     int retPrice  = Credit - products[currProduct].Price;
  103.  
  104.     lcd.clear();
  105.     lcd.print("Vissza:");
  106.     lcd.setCursor(0,1);
  107.     lcd.print(retPrice);
  108.     lcd.print(" Ft");
  109.     Credit = 0;
  110.     delay(3000);
  111.     currState = PENZBEDOBAS;
  112. }
  113.  
  114. void setup()
  115. {
  116.   Serial.begin(115200);
  117.   pinMode(8, INPUT);
  118.   pinMode(9, INPUT);
  119.   pinMode(7, INPUT);
  120.  
  121.  
  122.   strip.begin();
  123.   strip.show(); // Initialize all pixels to 'off'
  124.  
  125.   // set up the LCD's number of columns and rows:
  126.   lcd.begin(16, 2);
  127.   // Print a message to the LCD.
  128.   lcd.setCursor(0, 0);
  129.   lcd.print("Udvozoljuk!");
  130.   delay(2000);
  131.   lcd.clear();
  132. }
  133.  
  134. void loop()
  135. {
  136.   switch(currState)
  137.   {
  138.     case PENZBEDOBAS:
  139.         penzBedobas();
  140.     break;
  141.     case VARAKOZAS:
  142.         varakozas();
  143.     break;
  144.     case HITELVIZSGALAT:
  145.         hitelVizsgalat();
  146.     break;
  147.     case KIADAS:
  148.         kiadas();
  149.     break;    
  150.     case PENZVISSZAADAS:
  151.         penzvisszaadas();
  152.     break;
  153.     default: delay(1000); break;  
  154.   }
  155.  
  156.    
  157.   delay(1000); // Wait for 1000 millisecond(s)
  158. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×