However, I now would like to take this counter value and output it to pins D2 - D9
Are the D2-D9 pins not allready used in your sketch? LCD etc?
What do I do in order to "print" the counter value to the 8 pins?
Consider a shiftOut and a 74HC595 , uses less pins - http://www.arduino.cc/en/Tutorial/ShiftOut -
Furthermore you should add this line at the end:
buttonPushCounter = constrain(buttonPushCounter, 0, 255); // adjust numbers if needed
to keep its value within defined range for the ADC
int upTenButtonState = digitalRead(upTenButtonPin);
if (upTenButtonState != lastUpTenButtonState) {
if (upTenButtonState == HIGH) {
buttonPushCounter += 10;
}
}
lastUpTenButtonState = upTenButtonState;
int upOneButtonState = digitalRead(upOneButtonPin);
if (upOneButtonState != lastUpOneButtonState) {
if (upOneButtonState == HIGH) {
buttonPushCounter ++;
}
}
lastUpOneButtonState = upOneButtonState;
int downOneButtonState = digitalRead(downOneButtonPin);
if (downOneButtonState != lastDownOneButtonState) {
if (downOneButtonState == HIGH) {
buttonPushCounter --;
}
}
lastDownOneButtonState = downOneButtonState;
int downTenButtonState = digitalRead(downTenButtonPin);
if (downTenButtonState != lastDownTenButtonState) {
if (downTenButtonState == HIGH) {
buttonPushCounter -= 10;
}
}
lastDownTenButtonState = downTenButtonState;
can be shortened
- reuse the var to hold the read value
- that var can be an uint8_t (one byte as it only holds 0 or 1)
- merge the if statements with AND &&
- make the compares easier (compare with a constant, esp LOW==0 is easier)
uint8_t button = digitalRead(upTenButtonPin);
if (button == HIGH && lastUpTenButtonState == LOW) buttonPushCounter += 10;
lastUpTenButtonState = button ;
button = digitalRead(upOneButtonPin);
if (button == HIGH && lastUpOneButtonState == LOW ) buttonPushCounter ++;
lastUpOneButtonState = button;
button = digitalRead(downTenButtonPin);
if (button == HIGH && lastDownTenButtonState == LOW) buttonPushCounter -= 10;
lastUpTenButtonState = button ;
button = digitalRead(downOneButtonPin);
if (button == HIGH && lastDownOneButtonState == LOW ) buttonPushCounter--;
lastUpOneButtonState = button;