hello and good day, I am relatively new to programming and I am here trying to find out why is my output is not as per what I expected below is what my sketch looks like
const int tw1_pin1 = 13;
const int tw1_pin2 = 12;
const int tw1_pin4 = 11;
const int tw1_pin8 = 10;
const int tw2_pin1 = 47;
const int tw2_pin2 = 49;
const int tw2_pin4 = 51;
const int tw2_pin8 = 53;
int tw1_pin_one;
int tw1_pin_two;
int tw1_pin_four;
int tw1_pin_eight;
int tw2_pin_one;
int tw2_pin_two;
int tw2_pin_four;
int tw2_pin_eight;
void setup() {
pinMode(tw1_pin1, INPUT);
pinMode(tw1_pin2, INPUT);
pinMode(tw1_pin4, INPUT);
pinMode(tw1_pin8, INPUT);
pinMode(tw2_pin1, INPUT);
pinMode(tw2_pin2, INPUT);
pinMode(tw2_pin4, INPUT);
pinMode(tw2_pin8, INPUT);
Serial.begin(9600);
}
void loop() {
tw1_pin_one = digitalRead(tw1_pin1);
tw1_pin_two = digitalRead(tw1_pin2);
tw1_pin_four = digitalRead(tw1_pin4);
tw1_pin_eight = digitalRead(tw1_pin8);
tw2_pin_one = digitalRead(tw2_pin1);
tw2_pin_two = digitalRead(tw2_pin2);
tw2_pin_four = digitalRead(tw2_pin4);
tw2_pin_eight = digitalRead(tw2_pin8);
unsigned char thumbwheel1 = 0;
thumbwheel1 += digitalRead(tw1_pin1);
thumbwheel1 += 2 * digitalRead(tw1_pin2);
thumbwheel1 += 4 * digitalRead(tw1_pin4);
thumbwheel1 += 8 * digitalRead(tw1_pin8);
if (thumbwheel1 == 1)
{
Serial.print("TW1 = 1 ");
}
if (thumbwheel1 == 2)
{
Serial.print("TW1 = 2 ");
}
if (thumbwheel1 == 3)
{
Serial.print("TW1 = 2 ");
}
if (thumbwheel1 == 4)
{
Serial.print("TW1 = 4 ");
}
if (thumbwheel1 == 5)
{
Serial.print("TW1 = 5 ");
}
if (thumbwheel1 == 6)
{
Serial.print("TW1 = 6 ");
}
if (thumbwheel1 == 7)
{
Serial.print("TW1 = 7 ");
}
if (thumbwheel1 == 8)
{
Serial.print("TW1 = 8 ");
}
if (thumbwheel1 == 9)
{
Serial.print("TW1 = 9 ");
}
if (thumbwheel1 == 0)
{
Serial.print("TW1 = 0 ");
}
unsigned char thumbwheel2 = 0;
thumbwheel2 += digitalRead(tw2_pin1);
thumbwheel2 += 2 * digitalRead(tw2_pin2);
thumbwheel2 += 4 * digitalRead(tw2_pin4);
thumbwheel2 += 8 * digitalRead(tw2_pin8);
if (thumbwheel2 == 1)
{
Serial.print("TW2 = 1 ");
}
if (thumbwheel2 == 2)
{
Serial.print("TW2 = 2 ");
}
if (thumbwheel2 == 3)
{
Serial.print("TW2 = 3 ");
}
if (thumbwheel2 == 4)
{
Serial.print("TW2 = 4 ");
}
if (thumbwheel2 == 5)
{
Serial.print("TW2 = 5 ");
}
if (thumbwheel2 == 6)
{
Serial.print("TW2 = 6 ");
}
if (thumbwheel2 == 7)
{
Serial.print("TW2 = 7 ");
}
if (thumbwheel2 == 8)
{
Serial.print("TW2 = 8 ");
}
if (thumbwheel2 == 9)
{
Serial.print("TW2 = 9 ");
}
if (thumbwheel2 == 0)
{
Serial.print("TW2 = 0 ");
}
unsigned char total = 0;
total = thumbwheel1 + thumbwheel2;
Serial.println("total: " + String(total));
delay(1000);
}
below is what I got when I run the sketch
TW1 = 9 TW2 = 9 total: 18
what I want is
TW1 = 9 TW2 = 9 total: 99
I`m using a thumbwheel that read BCD and trying to merge both to make double digit. Can I know where in the part of my sketch is wrong and how do I fix it.