Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int tens, ones;
- int temp1,temp2,temp4,temp8;
- void setup() {
- pinMode(2, INPUT); //the one spot of BCD (ONES)
- pinMode(3, INPUT); //the two spot of BCD (ONES)
- pinMode(4, INPUT); //the four spot of BCD (ONES)
- pinMode(5, INPUT); //the eight spot of BCD (ONES)
- // pinMode(6 to 10) inputs - same as above but for the tens digit
- Serial.begin(9600);
- }
- void loop() {
- //you would probably read the tens digit first...it may not matter..
- //Read the ONES digit
- if (digitalRead(2)) { temp1 = 1; } else {temp1 = 0;} //if this is high it will set the bit to the number it should be
- if (digitalRead(3)) { temp2 = 2; } else {temp2 = 0;}
- if (digitalRead(4)) { temp4 = 4; } else {temp4 = 0;}
- if (digitalRead(5)) { temp8 = 8; } else {temp8 = 0;}
- ones = temp1 + temp2 + temp4 + temp8;
- //Read the TENS digit the same as above with the same temp variables
- tens = temp1 + temp2 + temp4 + temp8;
- Serial.print(tens);
- Serial.println(ones);
- //If you need this as a number not two digits you could do something like this.
- int number;
- number = (tens*10) + ones;
- Serial.println(tens);
- }
- //That is probably how I read the BCD switches...
Add Comment
Please, Sign In to add comment