I've got a 2-Digit seven segment display that i want to count down from 99 to 00 when i pull a trigger.
I've used this code and library: Arduino and 2-Digit Seven Segment Module - Ardumotive Arduino Greek Playground
and modified it.
I get as far as starting the counddown with the trigger, but it doeesn't paus when the trigger is released.
I need it to just pause and not reset.
BONUS:
If at all possible i would like it to count faster, and restart from 99 when it has reached 00 as well.
#include <ShiftRegister74HC595.h>
// create shift register object (number of shift registers, data pin, clock pin, latch pin)
ShiftRegister74HC595 sr (2, 2, 3, 4);
int number = 99; // <--- Change it from 0 to 99
int value, digit1, digit2, digit3, digit4;
uint8_t numberB[] = {B11000000, //0
B11111001, //1
B10100100, //2
B10110000, //3
B10011001, //4
B10010010, //5
B10000011, //6
B11111000, //7
B10000000, //8
B10011000 //9
};
const int trigger = 3; // the number of the trigger pin
const int boxled = 5; // the number of the box LED pin to the display
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
pinMode(boxled, OUTPUT);
pinMode(trigger, INPUT);
}
void loop()
{ buttonState = digitalRead(trigger);
if (buttonState == HIGH)
countDown();
}
// else
// countdown pauses when trigger is released and resumes when pressed again
void countDown() {
for (number; number >= 0; number--) {
//Split number to digits:
digit2 = number % 10 ;
digit1 = (number / 10) % 10 ;
//Send them to 7 segment displays
uint8_t numberToPrint[] = {numberB[digit2], numberB[digit1]};
sr.setAll(numberToPrint);
//Reset them for next time
digit1 = 0;
digit2 = 0;
delay(1000); // Repeat every 1 sec
}
}