Advertisement
adolf01

Untitled

Jul 1st, 2017
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.96 KB | None | 0 0
  1. #define LED 8
  2. bool SwitchF[8] = {true, true, true, true, true, true, true, true};
  3. int SwitchState[8] = {0, 0, 0, 0, 0, 0, 0, 0};
  4. bool BlinkF[8] = {false, false, false, false, false, false, true, true,};
  5. int BlinkState[8] = {0, 0, 0, 0, 0, 0, 0, 0};
  6. long BlinkTime[8];
  7. int LastState[8];
  8. int INPins[8] = {7, 6, 5, 1, 0, 4, 3, 2};
  9. int OUTPins[8] = {9, 10, A0, A1, A2, A3, A4, A5};
  10. long blikacka = 0 ;
  11. int blika = 0;
  12. long starttime = millis();
  13.  
  14. void setup() {
  15.   pinMode(LED, OUTPUT);
  16.   for (int i = 0; i < 8; i++) {
  17.     pinMode(INPins[i], INPUT);
  18.     pinMode(OUTPins[i], OUTPUT);
  19.  
  20.   }
  21.  
  22. }
  23.  
  24. void loop() {
  25.   starttime = millis();
  26.   // put your main code here, to run repeatedly:
  27.   for (int i = 0; i < 8; i++) {
  28.     if (LastState[i] != digitalRead(INPins[i])) {
  29.       LastState[i] = digitalRead(INPins[i]);
  30.       if (SwitchF[i]) {
  31.         if (LastState[i] == 0) {
  32.           if (SwitchState[i] == 0)  {
  33.             digitalWrite(OUTPins[i], HIGH);
  34.             SwitchState[i] = 1;
  35.             BlinkTime[i] = millis();
  36.             if (BlinkF) BlinkState[i] = 1;
  37.           } else {
  38.             digitalWrite(OUTPins[i], LOW);
  39.             SwitchState[i] = 0;
  40.           }
  41.         }
  42.       } else {
  43.         digitalWrite(OUTPins[i], LastState[i]);
  44.       }
  45.     }
  46.     if (SwitchF[i]) {
  47.       if (BlinkF[i]) {
  48.         if (SwitchState[i] == 1) {
  49.  
  50.           if (millis() - BlinkTime[i] >= 400) {
  51.             BlinkTime[i] = millis();
  52.             if (BlinkState[i] == 1) {
  53.               digitalWrite(OUTPins[i], LOW);
  54.               BlinkState[i] = 0;
  55.             } else {
  56.  
  57.               digitalWrite(OUTPins[i], HIGH);
  58.               BlinkState[i] = 1;
  59.             }
  60.           }
  61.         }
  62.       }
  63.     }
  64.     //Kontrolka behu MCU
  65.  
  66.     if (millis() - blikacka >= 400) {
  67.       blikacka = millis();
  68.       if (blika == 1) {
  69.         digitalWrite(LED, LOW);
  70.         blika = 0;
  71.       } else {
  72.         digitalWrite(LED, HIGH);
  73.         blika = 1;
  74.       }
  75.     }
  76.  
  77.   }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement