Guest User

Untitled

a guest
Sep 22nd, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. int tens, ones;
  2. int temp1,temp2,temp4,temp8;
  3.  
  4. void setup() {
  5. pinMode(2, INPUT); //the one spot of BCD (ONES)
  6. pinMode(3, INPUT); //the two spot of BCD (ONES)
  7. pinMode(4, INPUT); //the four spot of BCD (ONES)
  8. pinMode(5, INPUT); //the eight spot of BCD (ONES)
  9.  
  10. // pinMode(6 to 10) inputs - same as above but for the tens digit
  11. Serial.begin(9600);
  12. }
  13.  
  14. void loop() {
  15. //you would probably read the tens digit first...it may not matter..
  16.  
  17.  
  18. //Read the ONES digit
  19. if (digitalRead(2)) { temp1 = 1; } else {temp1 = 0;} //if this is high it will set the bit to the number it should be
  20. if (digitalRead(3)) { temp2 = 2; } else {temp2 = 0;}
  21. if (digitalRead(4)) { temp4 = 4; } else {temp4 = 0;}
  22. if (digitalRead(5)) { temp8 = 8; } else {temp8 = 0;}
  23.  
  24. ones = temp1 + temp2 + temp4 + temp8;
  25.  
  26. //Read the TENS digit the same as above with the same temp variables
  27.  
  28. tens = temp1 + temp2 + temp4 + temp8;
  29.  
  30. Serial.print(tens);
  31. Serial.println(ones);
  32.  
  33. //If you need this as a number not two digits you could do something like this.
  34.  
  35. int number;
  36. number = (tens*10) + ones;
  37.  
  38. Serial.println(tens);
  39.  
  40. }
  41.  
  42. //That is probably how I read the BCD switches...
Add Comment
Please, Sign In to add comment