Advertisement
WielkaSpluwa

Strzelba

Jul 19th, 2019
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.16 KB | None | 0 0
  1. //int analogTrigerIn = A5; //spust in PIN
  2. int IK = 9; // spust out PIN
  3. int SPUST = 4;  // spust
  4. int POMPA = 7; //pompa
  5. int LED = 13;
  6.  
  7. bool shak = false;
  8. bool lak = false;
  9. bool executeShot = false;
  10.  
  11. const int MIN_RELOAD_DELAY = 20;
  12. int reloadCounter = 0;
  13.  
  14. void setup() {
  15.   Serial.begin(2000000);
  16. }
  17.  
  18.  
  19.  
  20. void strzal () {
  21.   analogWrite(IK,255);
  22.   delay(40);
  23.   analogWrite(IK,0);
  24.     delay(40);
  25.   analogWrite(IK,255);
  26.   executeShot=false;
  27.   Serial.println("shot");
  28. }
  29.  
  30.  
  31.  
  32.  
  33. void loop() {
  34.  
  35.     if (digitalRead(POMPA) == HIGH && digitalRead(SPUST) == LOW) {
  36.       shak = true;
  37.       lak = false;
  38.       reloadCounter = MIN_RELOAD_DELAY;
  39.     }
  40.  
  41.     if(shak && reloadCounter > 0 && digitalRead(POMPA) == LOW)
  42.     {
  43.       reloadCounter--;
  44.       if(reloadCounter <= 0)
  45.       {
  46.         lak = true;
  47.       }
  48.       delay(1);
  49.     }
  50.  
  51.     if (lak && digitalRead(SPUST) == HIGH)  {
  52.    
  53.       executeShot = true;
  54.       shak = false;
  55.       lak = false;
  56.     }
  57.    
  58.     if(lak)
  59.     {
  60.        digitalWrite(LED,HIGH);
  61.     }
  62.     else
  63.     {
  64.       digitalWrite(LED,LOW);
  65.     }
  66.    
  67.     if(executeShot)
  68.     {
  69.       strzal();
  70.     }
  71.   delay(1);
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement