Afficheur 7 segments 4 digits piloté par un TM1636

Avec le TickShield j'ai eu ce programme en demo

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

Cordialement chris 62

Même pas un tout petit ?

Personnellement j'utilise un module TM1637 avec la librairie qui va avec et c'est très simple à comprendre et à coder :wink:

Sinon j'ai jamais utilisé ce Shield donc je peux pas t'aider.

Bonjour Bichongri

As tu un programme ( avec ton tm1637) qui à partir d'un pb incrémente l afficheur de 1 à chaque appui

Cordialement chris62

hello
teste ça

c'est un bête chrono qui tourne en 1637 avec tm1637.h

j'ai testé avec tm1636.h en adaptant le code, c'est ok

à toi d'y mettre un BP

#include <TimerOne.h>
#include "TM1636.h"
#define ON 1
#define OFF 0

int8_t TimeDisp[] = {0x00,0x00,0x00,0x00};
unsigned char ClockPoint = 1;
unsigned char Update;
unsigned char halfsecond = 0;
unsigned char second=0;
unsigned char minute = 0;
unsigned char hour = 0;


#define CLK A4//pins definitions for TM1636 and can be changed to other ports       
#define DIO A5
TM1636 tm1636(CLK,DIO);

void setup()
{
  tm1636.set();
  tm1636.init();
  Timer1.initialize(500000);//timing for 500ms
  Timer1.attachInterrupt(TimingISR);//declare the interrupt serve routine:TimingISR  
}
void loop()
{
  if(Update == ON)
  {
    TimeUpdate();
    tm1636.display(TimeDisp);
  }
  
}
void TimingISR()
{
  halfsecond ++;
  Update = ON;
  if(halfsecond == 2){
    second ++;
    if(second == 60)
    {
      minute ++;
      if(minute == 60)
      {
        hour ++;
        if(hour == 24)hour = 0;
        minute = 0;
      }
      second = 0;
    }
    halfsecond = 0;  
  }
 // Serial.println(second);
  ClockPoint = (~ClockPoint) & 0x01;
}
void TimeUpdate(void)
{
  if(ClockPoint)tm1636.point(POINT_ON);
  else tm1636.point(POINT_OFF); 
  //TimeDisp[0] = hour / 10;
  //TimeDisp[1] = hour % 10;
  TimeDisp[0] = minute / 10;
  TimeDisp[1] = minute % 10;
  TimeDisp[2] = second / 10;
  TimeDisp[3] = second % 10;
    Update = ON;
  //Update = OFF;
}

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);
}

Bonjour et merci pour votre aide

J'ai refait le programme de kamill

#include "TM1636.h"

#define BP 10

TM1636 tm1636(7,8);

unsigned long compteur = 0;

void setup()
{
  Serial.begin(9600);
  tm1636.init();
  pinMode(BP, INPUT_PULLUP);
 
}

void loop()
{
  if (!digitalRead(BP)) 
  {
    delay(20); // anti rebond en dur!
    compteur ++; // compte le nombre de 1 à afficher
    Serial.print("Compteur : ");
    Serial.println (compteur);
    
  while (!digitalRead(BP));
    display (compteur);
    delay(20);
  }
  }
  
  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);
    
}

J ai deux questions

  1. quelqu'un peut il m expliquer la fonction void display (ini val )

  2. le proramme fonctionne mais se bloque
    parfois il s arrete à 38 parfois 60 etc

Merci pour votre aide

Cordialement Chris

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

pour l instant la valeur max obtenue est de 68 impulsions

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);

à quoi sert la boucle for ?

disp*=val%10; pourquoi val%10 ?*
et ensuite val/10 ?

La boucle for c'est pour traiter les 4 chiffres
val%10 c'est le reste de la division par 10
val/10 ça donne le nombre de dizaine, puis centaines...

val=4567

  1. val%10 -> 7 val/10 -> 456
  2. val%10 -> 6 val/10 -> 45
  3. val%10 -> 5 val/10 -> 4
  4. val%10 -> 4 val/10 -> 0

merci kamil pour ta précieuse aide

me reste à bien assimiler tout cela

cordialement