Advertisement
arkturius

Untitled

Dec 26th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.56 KB | None | 0 0
  1. #include <Wire.h>
  2. #include <LiquidCrystal_I2C.h>
  3. #include <Servo.h>
  4.  
  5. Servo servo;
  6.  
  7. LiquidCrystal_I2C lcd(0x27, 16, 2);
  8.  
  9. int photoResistorsPins[8] = {0,1,2,3,4,5,6,7};
  10. int coinValues[8] = {0.01,0.02,0.05,0.1,0.2,0.5,1,2};
  11. int money = 0;
  12.  
  13. bool isWorking = false;
  14. bool isPassed = false;
  15.  
  16. void setup()
  17. {
  18.   lcd.begin(16,2);
  19.   servo.attach(10);
  20.   lcd.setBacklight((uint8_t)1);
  21.  
  22.   for(int i=0; i<8; i++){                         //Toutes les photorésistances
  23.     pinMode(i,INPUT);
  24.   }
  25.  
  26.   pinMode(8,OUTPUT);                              //Les 4 premières LED
  27.   pinMode(9,OUTPUT);                              //Les 4 suivantes
  28.  
  29.   pinMode(10,INPUT);                              //Un bouton Marche/Arrêt
  30.  
  31.   servo.write(0);
  32.   lcd.print("Solde :");
  33.   lcd.setCursor(0,1);
  34.   lcd.print(money);
  35. }
  36.  
  37. void loop()
  38. {
  39.   lcd.clear();
  40.   lcd.setCursor(0,0);
  41.   lcd.print("Solde :");
  42.   lcd.setCursor(0,1);
  43.   lcd.print(money);
  44.  
  45.   if(isWorking){
  46.    
  47.     digitalWrite(8,HIGH);
  48.     digitalWrite(9,HIGH);
  49.    
  50.     if(digitalRead(10) == HIGH){
  51.       isWorking = !isWorking;
  52.     }
  53.    
  54.     if(isPassed){
  55.       delay(100);
  56.       servo.write(10);
  57.       isPassed = false;
  58.       servo.write(0);
  59.     }
  60.    
  61.     while(!isPassed){
  62.       for(int i=0; i<8; i++){
  63.         if(digitalRead(i) == LOW){
  64.           money += coinValues[i];
  65.           isPassed = true;
  66.           break;
  67.         }
  68.       }
  69.     }
  70.    
  71.   }else{
  72.    
  73.     digitalWrite(8,LOW);
  74.     digitalWrite(9,LOW);
  75.    
  76.     if(digitalRead(10) == HIGH){
  77.       isWorking = !isWorking;
  78.     }
  79.   }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement