I am going back to basics so have started with just the bcd code. I have moved the bcd code to setup and it all seems to work. The serial output at the bottom is just so i could test it.
I just have a few questions:
Does it make sense and does it conform to a more logical layout?
Should I be defining constants as byte or uint8_t or should I have left them as int?
Are byte and uint8_t actually the same type?
Should I be using byte at all? It seemed to me that byte could be used for storing number of 0 - 255 and that is all I need.
/* Bulb Counter
*
*/
/* Define const pins For BCD PushWheels */
const byte tq1 = 2;
const byte tq2 = 3;
const byte tq4 = 4;
const byte tq8 = 5;
const byte uq1 = 6;
const byte uq2 = 7;
const byte uq4 = 8;
const byte uq8 = 9;
/* End Define for BCD PushWheels */
byte bcdtot;
byte ttot;
byte utot;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
delay(50);
/* Set BCD Pins to be INPUTS */
/* TENS PushWheel */
pinMode(tq1, INPUT); // tens-thumbwheel '1'
pinMode(tq2, INPUT); // tens-thumbwheel '2'
pinMode(tq4, INPUT); // tens-thumbwheel '4'
pinMode(tq8, INPUT); // tens-thumbwheel '8'
/* UNITS PushWheel */
pinMode(uq1, INPUT); // units-thumbwheel '1'
pinMode(uq2, INPUT); // units-thumbwheel '2'
pinMode(uq4, INPUT); // units-thumbwheel '4'
pinMode(uq8, INPUT); // units-thumbwheel '8'
/* End Define BCD Pins */
if (digitalRead(tq1)==HIGH) { ttot+=1; }
if (digitalRead(tq2)==HIGH) { ttot+=2; }
if (digitalRead(tq4)==HIGH) { ttot+=4; }
if (digitalRead(tq8)==HIGH) { ttot+=8; }
if (digitalRead(uq1)==HIGH) { utot+=1; }
if (digitalRead(uq2)==HIGH) { utot+=2; }
if (digitalRead(uq4)==HIGH) { utot+=4; }
if (digitalRead(uq8)==HIGH) { utot+=8; }
bcdtot=ttot*10+utot;
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("ttot");
Serial.println(ttot);
delay(1000);
Serial.println(digitalRead(tq1));
Serial.println(digitalRead(tq2));
Serial.println(digitalRead(tq4));
Serial.println(digitalRead(tq8));
Serial.println("utot");
Serial.println(utot);
delay(1000);
Serial.println(digitalRead(uq1));
Serial.println(digitalRead(uq2));
Serial.println(digitalRead(uq4));
Serial.println(digitalRead(uq8));
delay(1000);
Serial.println("bcdtot");
Serial.println(bcdtot);
delay(1000);
}