int pushbutton = 11; //define pushputton pin
void setup() {
DDRD = B11111110; //set up seg a-g
PORTD = 0;
pinMode (pushbutton, INPUT);
}
//define count & max count & button states
int count = 0;
int buttonState = 0;
int lastButtonState = LOW;
int maxCount = 16;
void loop() {
buttonState = digitalRead(pushbutton); //read current button state
//For 0-f, Set segments according to the hexadecimal digit using
// ports instead of hundreds of digitalwrites
PORTD = B11111100;//0
delay(1000);
if (buttonState == HIGH && lastButtonState == LOW) // check if button is pressed
{count++; // increment counter
if (count >= maxCount) {
count = 0; } //repeat back to zero once maxxed out @ 15 (aka f)
PORTD = B01100000;//1
delay(1000);
if (buttonState == HIGH && lastButtonState == LOW) {
count++;
if (count >= maxCount) {
count = 0;}
PORTD = B11011010;//2
delay(1000);
if (buttonState == HIGH && lastButtonState == LOW) {
count++;
if (count >= maxCount) {
count = 0;}
PORTD = B11110010;//3
delay(1000);
if (buttonState == HIGH && lastButtonState == LOW) {
count++;
if (count >= maxCount) {
count = 0;}
PORTD = B01100110;//4
delay(1000);
if (buttonState == HIGH && lastButtonState == LOW) {
count++;
if (count >= maxCount) {
count = 0;}
PORTD = B10110110;//5
delay(1000);
if (buttonState == HIGH && lastButtonState == LOW) {
count++;
if (count >= maxCount) {
count = 0;}
PORTD = B10111110;//6
delay(1000);
if (buttonState == HIGH && lastButtonState == LOW) {
count++;
if (count >= maxCount) {
count = 0;}
PORTD = B11100000;//7
delay(1000);
if (buttonState == HIGH && lastButtonState == LOW) {
count++;
if (count >= maxCount) {
count = 0;}
PORTD = B11111110;//8
delay(1000);
if (buttonState == HIGH && lastButtonState == LOW) {
count++;
if (count >= maxCount) {
count = 0;}
PORTD = B11110110;//9
delay(1000);
if (buttonState == HIGH && lastButtonState == LOW) {
count++;
if (count >= maxCount) {
count = 0;}
PORTD = B11101110;//A
delay(1000);
if (buttonState == HIGH && lastButtonState == LOW) {
count++;
if (count >= maxCount) {
count = 0;}
PORTD = B00111110;//b
delay(1000);
if (buttonState == HIGH && lastButtonState == LOW) {
count++;
if (count >= maxCount) {
count = 0;}
PORTD = B10011100;//c
delay(1000);
if (buttonState == HIGH && lastButtonState == LOW) {
count++;
if (count >= maxCount) {
count = 0;}
PORTD = B01111010;//d
delay(1000);
if (buttonState == HIGH && lastButtonState == LOW) {
count++;
if (count >= maxCount) {
count = 0;}
PORTD = B10011110;//E
delay(1000);
if (buttonState == HIGH && lastButtonState == LOW) {
count++;
if (count >= maxCount) {
count = 0;}
PORTD = B10001110;//F
delay(1000);
if (buttonState == HIGH && lastButtonState == LOW) {
count++;
if (count >= maxCount) {
count = 0;}
//Serial.println(count);
//count++; *for debugging*
}}}}}}}}}}}}}}}}
}
// I was able to get the button to enable correctly to go from 0-1, but I am not too sure
// as to why it wouldn't apply to the other hex #'s, 2-f