Hi
i have a big problem and i am stuck in how to fix it. i am creating a countdown timer which starts from 24 seconds and countdown to 0, this countdown timer also includes a single digit for milliseconds. the milliseconds count upwards from 0 to 10 then back to 0 and so on, once it hits zero the seconds go down by one. the digits look like this ( 24.0 ), 24 being the seconds and 0 being the milliseconds. my code works as it counts down the right way, however the numbers stop at 1.9 and never reaches 0.0. I have added a delay as there will be a buzzer going off for two seconds before the reset happens automatically. over all the timer is not reaching 0.0 but counts down the right way.
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#ifndef PSTR
#define PSTR
#endif
#define PIN 6
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(32, 8, PIN,
NEO_MATRIX_TOP + NEO_MATRIX_LEFT +
NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG,
NEO_GRB + NEO_KHZ800);
const uint16_t colors[] = {
matrix.Color(255, 255, 0) , matrix.Color(255, 255, 0), matrix.Color(255, 255, 0) };
const int buttonPin = 2; // the number of the pushbutton pin
int buttonState = 0;
int ms1 = 0;
int s = 24;
int validate = 0;
//String s_string = "";
int button_check = 0;
int check = 0;
int ledPin = 11;
void setup() {
matrix.begin();
matrix.setTextWrap(false);
matrix.setBrightness(40);
matrix.setTextColor(colors[0]);
Serial.begin(9600);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
}
int x = matrix.width();
int pass = 0;
void loop() {
/////////////////////////////////////////////////////////////////////////////////////////////////////
buttonState = digitalRead(buttonPin);
///////////////////////////////////////////////////////////////////////////////////////////////////// push is LOW
if (button_check == 0){
if (buttonState == HIGH) {
// digitalWrite(ledPin, HIGH);
check = 0;
validate = 1;
}
if (buttonState == LOW) {
button_check = 1;
check = 1;
validate = 0;
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
if (check == 1){
ms1++;
if(ms1 == 10){
ms1 = 0;
s--;
if(s == 0 && ms1 == 0){
check = 0;
s = 0;
ms1 = 0;
digitalWrite(ledPin, HIGH);
delay(2000);
digitalWrite(ledPin, LOW);
validate = 1;
}
}
}
if(validate == 1){
button_check = 0;
ms1 = 0;
s = 24;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
String ms1_string = String(ms1);
//String ms2_string = String(ms2);
String s_string = String(s);
//String s2_string = String(s2);
matrix.fillScreen(0);
matrix.setCursor(4, 0);
matrix.print(s_string + "." + ms1_string);
if(--x < -36) {
x = matrix.width();
if(++pass >= 3) pass = 0;
matrix.setTextColor(colors[pass]);
}
matrix.show();
delay(100);
}