Contapezzi con display 7 segment

Flavi71:
Scusa il ritardo.
Lascia stare lo schema dei collegamenti del post #34. Quelli giusti sono:
buttonPin = D2 (pulsante del contatore)
buttonReset = D4 (pulsante di reset)
CLK = D9
LOAD-CS = D10
DIN = D12

Con questo codice DEVE funzionare:

 //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 9 is connected to the CLK
pin 10 is connected to LOAD
We have only a single MAX72XX.
*/
LedControl lc=LedControl(12,9,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:
    #define buttonPin 2 // the pin that the pushbutton is attached to
    #define 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;
int tmp=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() {
  // read the pushbutton input pin:
  buttonState = digitalRead(buttonPin);

// compare the buttonState to its previous state
  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == HIGH) {
      // if the current state is HIGH then the button went from off to on:
      contatore++;
     
        tmp=contatore;
        unita=tmp%10;
        tmp=tmp/10;
        decine=tmp%10;
        centinaia=tmp/10;

lc.setDigit(0,2,(byte)centinaia,false);
      lc.setDigit(0,1,(byte)decine,false);
      lc.setDigit(0,0,(byte)unita,false);
    }
   
    // Delay a little bit to avoid bouncing
    delay(50);
 
  // save the current state as the last state, for next time through the loop
  lastButtonState = buttonState;
}

// if the buttonreset is pressed reset the buttonpushcounter
  if  (digitalRead(buttonReset) == HIGH){
      (contatore = 0);
      lc.clearDisplay(0);
    }
}



Fammi sapere.
Flaviano

Ciao Flavi71 scusami per il ritardo, allora ho aggiunto una resistenza al pin ISET del max7219 ogni volta che premo il pulsante comincia a contare solo che lo stato iniziale del display è spento come premo si accende.. come faccio a farlo stare acceso al primo stato? ho notato anche che conta dall'ultima cifra.. mi spiego meglio: invece di contare 001, 002.. mi conta 100,200 e cosi via come risolvo?
GRAZIE per il tempo che mi stai dando :slight_smile:
Fammi sapere
FuryMan