Il affiche 0123 1234 2345 3456 et ainsi de suite à l infini
#include "TM1636.h"
//--Declare a TM1636 Class object that control the 4-digit display--//
TM1636 tm1636(7,8);
void setup()
{
/*Set the default brightness is BRIGHT_TYPICAL and clear the display*/
tm1636.init();
}
void loop()
{
int8_t NumTab[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};//index of 0~9,A,b,C,d,E,F
int8_t table_length;
table_length = sizeof(NumTab);//get the length of the number table: NumTab
int8_t disp[4];//store the index of the 4 digit to display.
unsigned char digit_index = 0;
unsigned char starting_index = 0;//starting index of NumTab
while(1)
{
digit_index = starting_index;
starting_index ++;
if(starting_index == table_length)
{
starting_index = 0;//start again
}
for(unsigned char BitSelect = 0;BitSelect < 4;BitSelect ++)
{
disp[BitSelect] = NumTab[digit_index];
digit_index ++;
if(digit_index == table_length) digit_index = 0;
}
tm1636.display(disp);//display on the 4-digit display.
delay(300);//display 4-digit number for 300ms and then it will change.
}
}
Moi ce que j 'aimerai savoir faire pour commencer c est lorsque j appui sur un pb l afficheur s'incrémente de 1 à caque fois ( soit 0 1 2 3 4 etc ...)
Donc si qq a un petit programme à me proposer je suis preneur
chriiss62:
Donc si qq a un petit programme à me proposer je suis preneur
Bonjour,
Essaies ça:
#include "TM1636.h"
// ---- constantes ------- //
const int KEY_MENU=11;
const int KEY_UP=10;
const int KEY_DOWN=9;
//--Declare a TM1636 Class object that control the 4-digit display--//
TM1636 tm1636(7,8);
void setup()
{
Serial.begin(115200);
/*Set the default brightness is BRIGHT_TYPICAL and clear the display*/
tm1636.init();
pinMode(KEY_MENU, INPUT_PULLUP);
pinMode(KEY_UP, INPUT_PULLUP);
pinMode(KEY_DOWN, INPUT_PULLUP);
}
void loop()
{
static int n=0;
static bool etatIncPrec=false;
bool etatInc=!digitalRead(KEY_UP);
if (etatInc!=etatIncPrec)
{
etatIncPrec=etatInc;
if (etatInc)
n++;
}
display(n);
delay(20);
}
// affichage du nombre val
//
void display(int val)
{
int8_t disp[4];
for (int i=4-1; i>=0; i--)
{
disp[i]=val%10;
val/=10;
}
tm1636.display(disp);
}
display() décompose le nombre en chiffres en commençant par la fin et les range dans le tableau disp[] avant d'appeler la fonction d'affichage en lui passant le tableau disp.
Il n'y a pas de raison que le programme bloque au bout d'un certain nombre.
if (!digitalRead(BPA))
{
delay(20); // anti rebond en dur!
compteur=0;
Serial.print("Compteur : ");
Serial.println (compteur);
while (!digitalRead(BPA));
display (compteur);
delay(20);
}
[/code
J ai rajouté un if pour pouvoir remettre le compteur à 0 en cours de comptage
Cela fonction je peux remettre à 0 quand le compte 0 1 2 3 4 remise a 0 avec BPA ok
Par contre impossible de remettre à 0 lors d un blocage du compteur