Advertisement
Guest User

Arduino exclusive Button 3 way

a guest
Dec 30th, 2011
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. /*
  2. exclusive button selector
  3.  */
  4.  
  5. boolean lit1 = 0;
  6. boolean lit2 = 0;
  7. boolean lit3 = 0;
  8. boolean B1old = 0;
  9. boolean B2old = 0;
  10. boolean B3old = 0;
  11. boolean B1new = 0;
  12. boolean B2new = 0;
  13. boolean B3new = 0;
  14. int Pi1 = 8;
  15. int Pi2 = 9;
  16. int Pi3 = 10;
  17. int Po1 = 11;
  18. int Po2 = 12;
  19. int Po3 = 13;
  20.  
  21. void setup() {                
  22.   pinMode(Pi1, INPUT);
  23.   pinMode(Pi2, INPUT);
  24.   pinMode(Pi3, INPUT);
  25.   pinMode(Po1, OUTPUT);
  26.   pinMode(Po2, OUTPUT);
  27.   pinMode(Po3, OUTPUT);
  28.   B1new = digitalRead(Pi1);
  29.   B1old = B1new;
  30.   B2new = digitalRead(Pi2);
  31.   B2old = B2new;
  32.   B3new = digitalRead(Pi3);
  33.   B3old = B3new;
  34. }
  35.  
  36. int x = 1;
  37.  
  38. void loop() {
  39.   if (x > 3) {
  40.     x = 1;
  41.   }
  42.   if (x = 1) {
  43.     B1old = B1new;
  44.     B1new = digitalRead(Pi1);
  45.     if (B1new > B1old) {
  46.       lit1 = 1;
  47.       lit2 = 0;
  48.       lit3 = 0;
  49.     }
  50.   }
  51.   if (x = 2) {
  52.     B2old = B2new;
  53.     B2new = digitalRead(Pi2);
  54.     if (B2new > B2old) {
  55.       lit1 = 0;
  56.       lit2 = 1;
  57.       lit3 = 0;
  58.     }
  59.   }
  60.   if (x = 3) {
  61.     B3old = B3new;    
  62.     B3new = digitalRead(Pi3);
  63.     if (B3new > B3old) {
  64.       lit1 = 0;
  65.       lit2 = 0;
  66.       lit3 = 1;
  67.     }
  68.   }
  69.   digitalWrite(Po1, lit1);
  70.   digitalWrite(Po2, lit2);
  71.   digitalWrite(Po3, lit3);
  72.   x++;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement