Avevi detto che fino a 90 contava, quindi dovrebbe funzionare.
Se contava fino a 90 adesso dovrebbe contare fino a 999, non vedo motivi perché non lo faccia!
Controlla anche i collegamenti elettronica.
Prova a vedere se cosi il programma funziona! Ho semplificato la lettura del pulsante togliendo l'antirimbalzo, io i pulsanti li uso cosi con un piccolo delay() e non ho problemi.
//State change detection (edge detection)
//We always have to include the library
#include "LedControl.h"
/*
Now we need a LedControl to work with.
pin 12 is connected to the DataIn
pin 11 is connected to the CLK
pin 10 is connected to LOAD
We have only a single MAX72XX.
*/
LedControl lc=LedControl(12,11,10,1);
/* The circuit:
- buttonpin attached to pin 2 from +5V
- buttonreset attached to pin 4 from +5V
- 10 kilohm resistor attached to pin 2&4 from ground
*/
// this constant won't change:
const int buttonPin = 2;// the pin that the pushbutton is attached to
const int buttonReset = 4;// the pin that the buttonreset is attached to
// Variables will change:
int contatore = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
int unita = 0;
int decine = 0;
int centinaia = 0;
void setup(){
/*
The MAX72XX is in power-saving mode on startup,
we have to do a wakeup call
*/
lc.shutdown(0,false);
/* Set the brightness to a medium values */
lc.setIntensity(0,8);
/* and clear the display */
lc.clearDisplay(0);
// initialize the button pin as a input:
pinMode(buttonPin, INPUT);
pinMode(buttonReset, INPUT);
}
void loop() {
if (digitalRead(buttonPin)==HIGH){
contatore++;
unita=contatore%10;
contatore=contatore/10;
decine=contatore%10;
centinaia=contatore/10;
lc.setDigit(0,2,(byte)centinaia,false);
lc.setDigit(0,1,(byte)decine,false);
lc.setDigit(0,0,(byte)unita,false);
}
if(contatore>999) contatore=0; // Ritorna a zero quando deve contare 1000
delay(200);
if (digitalRead(buttonReset) == HIGH){
(contatore = 0);
lc.clearDisplay(0);
}
}