Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- #include <Adafruit_NeoPixel.h>
- const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
- LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
- #define LED_PIN 10
- #define LED_COUNT 12
- Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
- int Credit = 0;
- typedef enum{
- PENZBEDOBAS = 0,
- VALASZTAS,
- KIADAS,
- PENZVISSZAADAS,
- VARAKOZAS,
- HITELVIZSGALAT
- } State;
- State currState = PENZBEDOBAS;
- typedef struct{
- int Price;
- char Name[16];
- }product_t;
- product_t products[3] = {
- {80,"Cola"},
- {100, "Fanta"},
- {120, "Tea"}
- };
- int currProduct = 0;
- void penzBedobas()
- {
- lcd.clear();
- lcd.print("Dobja be a penzt");
- delay(1000);
- currState = VARAKOZAS;
- }
- void varakozas()
- {
- if(!digitalRead(8))
- {
- Credit += 20;
- }
- if(!digitalRead(9))
- {
- currProduct = (currProduct + 1) % (sizeof(products) / sizeof(product_t));
- lcd.clear();
- lcd.print(products[currProduct].Name);
- lcd.setCursor(0,1);
- lcd.print(products[currProduct].Price);
- lcd.print(" Ft");
- delay(2000);
- }
- if(!digitalRead(7))
- {
- currState = HITELVIZSGALAT;
- return;
- }
- lcd.clear();
- lcd.print("Hitel:");
- lcd.setCursor(0,1);
- lcd.print(Credit);
- lcd.print(" Ft");
- currState = VARAKOZAS;
- }
- void hitelVizsgalat()
- {
- if(Credit >= products[currProduct].Price)
- currState = KIADAS;
- else
- currState = VARAKOZAS;
- }
- void kiadas()
- {
- strip.setPixelColor(0, 0, 255, 0);
- strip.show();
- lcd.clear();
- lcd.print("Keszul:");
- lcd.setCursor(0,1);
- lcd.print(products[currProduct].Name);
- analogWrite(6, 255);
- delay(3000);
- analogWrite(6, 0);
- strip.setPixelColor(0, 0, 0, 0);
- strip.show();
- currState = PENZVISSZAADAS;
- }
- void penzvisszaadas(){
- int retPrice = Credit - products[currProduct].Price;
- lcd.clear();
- lcd.print("Vissza:");
- lcd.setCursor(0,1);
- lcd.print(retPrice);
- lcd.print(" Ft");
- Credit = 0;
- delay(3000);
- currState = PENZBEDOBAS;
- }
- void setup()
- {
- Serial.begin(115200);
- pinMode(8, INPUT);
- pinMode(9, INPUT);
- pinMode(7, INPUT);
- strip.begin();
- strip.show(); // Initialize all pixels to 'off'
- // set up the LCD's number of columns and rows:
- lcd.begin(16, 2);
- // Print a message to the LCD.
- lcd.setCursor(0, 0);
- lcd.print("Udvozoljuk!");
- delay(2000);
- lcd.clear();
- }
- void loop()
- {
- switch(currState)
- {
- case PENZBEDOBAS:
- penzBedobas();
- break;
- case VARAKOZAS:
- varakozas();
- break;
- case HITELVIZSGALAT:
- hitelVizsgalat();
- break;
- case KIADAS:
- kiadas();
- break;
- case PENZVISSZAADAS:
- penzvisszaadas();
- break;
- default: delay(1000); break;
- }
- delay(1000); // Wait for 1000 millisecond(s)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement