/* created by Bertrand VANDEPORTAELE */ const int inputPin = 12; //signal d'entrée const int ledPin = 13; //broche 13=PB5 char val=0; char cpt=0; unsigned int cpt2=0; /* We start by including the library */ #include "LedControl.h" /* * Now we create a new LedControl. * We use pins 12,11 and 10 on the Arduino for the SPI interface * Pin 9 is connected to the DATA IN-pin of the first MAX7221 * Pin 11 is connected to the CLK-pin of the first MAX7221 * Pin 10 is connected to the LOAD(/CS)-pin of the first MAX7221 * There will only be a single MAX7221 attached to the arduino */ LedControl lc = LedControl(9, 11, 10, 1); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void displayvalue(unsigned int val) { lc.setChar(0, 0, '0'+val%10, false); lc.setChar(0, 1, '0'+(val/10)%10, false); lc.setChar(0, 2, '0'+(val/100)%10, false); lc.setChar(0, 3, '0'+(val/1000)%10, false); lc.setChar(0, 4, '0'+(val/10000)%10, false); } //////////////////////////////////////////////////////////////////////////////////////////// void setup() { // start serial port at 9600 bps: Serial.begin(115200); pinMode(ledPin, OUTPUT); pinMode(inputPin, INPUT); /* while(1) //pour test recopie simple { val = (PINB>>4) & 1; PORTB = (PORTB & 0xdf) | (val<<5); }*/ //wake up the MAX72XX from power-saving mode lc.shutdown(0, false); //set a medium brightness for the Leds lc.setIntensity(0, 8); // lc.setLed(0,2,7,true); lc.setChar(0, 0, ' ', false); lc.setChar(0, 1, ' ', false); lc.setChar(0, 2, ' ', false); lc.setChar(0, 3, ' ', false); lc.setChar(0, 4, ' ', false); lc.setChar(0, 5, ' ', false); lc.setChar(0, 6, ' ', false); lc.setChar(0, 7, ' ', false); cpt2=0; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void loop() { while(1) { while( ( (PINB>>4) & 1)==1); //attente front descendant cpt++; if (cpt>=5) //facteur de division /2 { // delayMicroseconds(150); PORTB = (PORTB & 0xdf) | (val<<5); cpt=0; if (val==0) val=1; else val=0; } displayvalue(cpt2); cpt2++; if (cpt2>10000) cpt2=0; while( ( (PINB>>4) & 1)==0); //attente front montant } }