Advertisement
adolf01

M-UNIT

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