Advertisement
adolf01

Untitled

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