daniel_lawson9999

Daniel, Andrew, Matthew Full Adder Arduino

Aug 30th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.12 KB | None | 0 0
  1. #define B1 2
  2. #define B2 4
  3. #define B3 3
  4. #define L1 7
  5. #define L2 5
  6.  
  7. boolean b1L=false;
  8. boolean b2L =false;
  9. boolean b3L =false;
  10. boolean debounce(boolean last, int pin){
  11.   boolean current = digitalRead(pin);
  12.   if(last!=current) {
  13.     delay (5);
  14.     current = digitalRead(pin);
  15.   }
  16.   return current;
  17.  
  18.  
  19. }
  20.  
  21. void setup() {
  22.   // put your setup code here, to run once:
  23.   pinMode(B1, INPUT);
  24.   pinMode(B2, INPUT);
  25.   pinMode(B3, INPUT);
  26.   pinMode(L1, OUTPUT);
  27.   pinMode(L2, OUTPUT);
  28.   Serial.begin(9600);
  29. }
  30.  
  31. void loop() {
  32.   boolean  b1A, b2A, b3A;
  33.   b1A = debounce(b1L, B1);
  34.   b2A = debounce(b2L, B2);
  35.   b3A = debounce(b3L, B3);
  36.  
  37.  
  38.  
  39. Serial.print(b1A);
  40. Serial.print(b2A);
  41. Serial.println(b3A);
  42.                     //one button             //don't turn on light if two or three
  43. digitalWrite(L1, (b1A ^ b2A ^b3A) && (!((b1A&&b2A)||(b1A&&b3A)||(b2A&&b3A)) || (b1A && b2A && b3A)));//||(b1A && b2A && b3A)
  44.                       //two buttons                 //don't turn on if three
  45. digitalWrite(L2, ((b1A&&b2A)||(b1A&&b3A)||(b2A&&b3A)) );
  46.                       //three buttons
  47.  
  48.   b1L = b1A;
  49.   b2L = b2A;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment