Compteur digital avec TM1637

bonsoir
je suis en train de me faire un intervalomètre pour un APN pour faire des poses plus longues en astrophoto
sauf que j'ai beau chercher mais je ne trouve pas/ comprends pas comment faire un compteur pour ces poses
voici mon code

#include <TM1637.h>

const int CLK = 2;
const int DIO = 3;

TM1637 tm(CLK, DIO);

int p5 = 5;
int p10 = 6;
int p20 = 7;
int p30 = 8;
int p60 = 9;
int p90 = 10;
int p120 = 11;
int p150 = 12;
int camera = 3;



void setup() {

  tm.init();
  tm.set(1);

  pinMode(camera, OUTPUT); //Pin 3 triggers camera via opto-isolator
  pinMode(p5, INPUT_PULLUP); //5 second input (pullups result in switch on = low)
  pinMode(p10, INPUT_PULLUP); //10 second input
  pinMode(p20, INPUT_PULLUP); //20 second input
  pinMode(p30, INPUT_PULLUP); //30 second input
  pinMode(p60, INPUT_PULLUP); //60 second input
  pinMode(p90, INPUT_PULLUP); //90 second input
  pinMode(p120, INPUT_PULLUP); //120 second input
  pinMode(p150, INPUT_PULLUP); //150 second input

  digitalWrite(camera,LOW);
}

// the loop function runs over and over again forever
void loop() {

  declenchements();

}

void declenchements () {

  if (digitalRead(p5) == LOW) {
    digitalWrite(camera, HIGH);

      delay(5000); //5 second delay
  } 
  if (digitalRead(p10) == LOW) {
    digitalWrite(camera, HIGH);

      delay(10000); //10 second delay
  }   
  if (digitalRead(p20) == LOW) {
    digitalWrite(camera, HIGH);

      delay(20000); //20 second delay
  } 
  if (digitalRead(p30) == LOW) {
    digitalWrite(camera,HIGH);

      delay(30000); //30 second delay
  } 
  if (digitalRead(p60) == LOW) {
    digitalWrite(camera, HIGH);

      delay(60000); //60 second delay
  }
  if (digitalRead(p90) == LOW) {
    digitalWrite(camera, HIGH);

      delay(90000); //90 second delay
  }
  if (digitalRead(p120) == LOW) {
    digitalWrite(camera, HIGH);

      delay(120000); //120 second delay
  }
  if (digitalRead(p150) == LOW) {
    digitalWrite(camera, HIGH);

      delay(150000); //150 second delay
  }
  else {
    digitalWrite(camera,LOW);
  }
  delay(3000);

}

ce que j'aimerais c'est que l'arduino compte les poses effectuées et qu'il affiche le nombre de poses sur un TM1637
merci d'avance :wink:
cdt :slight_smile:

Avez vous fait un programme qui affiche un
Compteur qui défile sur le TM1637?

Ça me fait penser à votre tuto :wink:
Il ne manque plus que le compteur de poses.
Il faudrait voir aussi côté anti rebond.

bonjour
j'ai récupéré un code de compteur sur le net mais c'est pour des boutons
les boutons up et dn sont eux par contre inversés

#include "TM1637.h"  // include TM1637 library
 
#define CLK   2  // define TM1637 clock pin
#define DIO   3  // define TM1637 data pin
 
#define UP    4  // define up button pin
#define DN    5  // define down button pin
 
// initialize the TM1637 library
TM1637 tm1637(CLK, DIO);
 
int num = 0, prev_num = 1;
 
void setup() {
  // initialize the TM1637 display
  tm1637.init();
  // set display brightness (from 0 to 7)
  tm1637.set(3);
 
  // configure UP and DN pins as inputs
  pinMode(UP, INPUT_PULLUP);
  pinMode(DN, INPUT_PULLUP);
}
 
// main loop
void loop() {
 
  if(num != prev_num)
  {  // if the displayed (current) number was changed
    prev_num = num;   // save current value of 'num'
    // print all data
    tm1637.display(0, num/1000);     // print thousands digit
    tm1637.display(1, num/100 % 10); // print hundreds digit
    tm1637.display(2, num/10 % 10);  // print tens digit
    tm1637.display(3, num% 10);      // print ones digit
 
    delay(200);  // wait 200 milliseconds
  }
  
  if( digitalRead(UP) )
  { // if the UP button is presses
    num++;         // increment 'num'
    if(num > 9999)
      num = 0;
  }
 
  if( digitalRead(DN) )
  { // if the DN button is presses
    num--;        // decrement 'num'
    if(num < 0)
      num = 9999;
  }
 
}
 
// end of code

par contre je ne sais pas comment adapter ce code au code de mon intervalomètre :slight_smile:
merci :wink:
cdt

hello
attention, dans ton 1er code:

Je ne comprend pas ton code, tu appuis sur un bouton pour déclencher une photo, x second après?
Ou tu appuis sur un bouton pour définir l'intervalle entre deux prise de vue?

C'est pas très compliqué mais d'abord est-ce que votre premier code fonctionne correctement ?
Est-ce que vous prenez vos photos correctement avec le temps d'exposition souhaité ?

oui j'ai déplacé le DIO du TM1637 sur la 4
oui les temps de poses sont justes et le code marche parfaitement
merci
cdt

je place le bouton sur on pour déclencher les photos
en fonction du bouton le temps de pose est de X ou X secondes :wink:
merci
cdt

D'accord je regarde ça dans la matinée.
Le temps de déjeuner et de regarder comment fonctionne votre
<TM1637.h>.

Essayez ça pour l'instant :

#include <TM1637.h>

const int CLK = 2;
const int DIO = 4;

TM1637  tm(CLK, DIO);

int p5 = 5;
int p10 = 6;
int p20 = 7;
int p30 = 8;
int p60 = 9;
int p90 = 10;
int p120 = 11;
int p150 = 12;
int camera = 3;

int num = 0;


void affiche() {
  tm.display(3, num % 10);     // print ones digit
  tm.display(2, num / 10 % 10); // print tens digit
  tm.display(1, num / 100 % 10); // print hundreds digit
  tm.display(0, num / 1000 % 10);   // print thousands digit
  delay(200);
}


void setup() {

  tm.init();
  tm.set(3);

  pinMode(camera, OUTPUT); //Pin 3 triggers camera via opto-isolator
  pinMode(p5, INPUT_PULLUP); //5 second input (pullups result in switch on = low)
  pinMode(p10, INPUT_PULLUP); //10 second input
  pinMode(p20, INPUT_PULLUP); //20 second input
  pinMode(p30, INPUT_PULLUP); //30 second input
  pinMode(p60, INPUT_PULLUP); //60 second input
  pinMode(p90, INPUT_PULLUP); //90 second input
  pinMode(p120, INPUT_PULLUP); //120 second input
  pinMode(p150, INPUT_PULLUP); //150 second input

  digitalWrite(camera, LOW);
}

// the loop function runs over and over again forever
void loop() {

  declenchements();

}

void declenchements () {

  if (digitalRead(p5) == LOW) {
    digitalWrite(camera, HIGH);

    delay(5000); //5 second delay
    num++;
    affiche(); 
  }
  if (digitalRead(p10) == LOW) {
    digitalWrite(camera, HIGH);

    delay(10000); //10 second delay
    num++;
    affiche();
  }
  if (digitalRead(p20) == LOW) {
    digitalWrite(camera, HIGH);

    delay(20000); //20 second delay
    num++;
    affiche(); 
  }
  if (digitalRead(p30) == LOW) {
    digitalWrite(camera, HIGH);

    delay(30000); //30 second delay
    num++;
    affiche();
  }
  if (digitalRead(p60) == LOW) {
    digitalWrite(camera, HIGH);

    delay(60000); //60 second delay
    num++;
    affiche(); 
  }
  if (digitalRead(p90) == LOW) {
    digitalWrite(camera, HIGH);

    delay(90000); //90 second delay
    num++;
    affiche(); 
  }
  if (digitalRead(p120) == LOW) {
    digitalWrite(camera, HIGH);

    delay(120000); //120 second delay
    num++;
    affiche();
  }
  if (digitalRead(p150) == LOW) {
    digitalWrite(camera, HIGH);

    delay(150000); //150 second delay
    num++;
    affiche();
  }
  else {
    digitalWrite(camera, LOW);
  }
  delay(3000);

}

dites-moi ce que ça donne ?
Merci.

Ok, c'est des boutons à deux position?
C'est pour ça que tu fais ta temporisation dans le IF.

Essayez ça également :

#include <TM1637.h>

const int CLK = 2;
const int DIO = 4;

TM1637  tm(CLK, DIO);

int p5 = 5;
int p10 = 6;
int p20 = 7;
int p30 = 8;
int p60 = 9;
int p90 = 10;
int p120 = 11;
int p150 = 12;
int camera = 3;

int num = 0;


void affiche(int num) {
  tm.display(3, num % 10);     // print ones digit
  tm.display(2, num / 10 % 10); // print tens digit
  tm.display(1, num / 100 % 10); // print hundreds digit
  tm.display(0, num / 1000 % 10);   // print thousands digit
  delay(200);
}


void setup() {

  tm.init();
  tm.set(3);

  pinMode(camera, OUTPUT); //Pin 3 triggers camera via opto-isolator
  pinMode(p5, INPUT_PULLUP); //5 second input (pullups result in switch on = low)
  pinMode(p10, INPUT_PULLUP); //10 second input
  pinMode(p20, INPUT_PULLUP); //20 second input
  pinMode(p30, INPUT_PULLUP); //30 second input
  pinMode(p60, INPUT_PULLUP); //60 second input
  pinMode(p90, INPUT_PULLUP); //90 second input
  pinMode(p120, INPUT_PULLUP); //120 second input
  pinMode(p150, INPUT_PULLUP); //150 second input

  digitalWrite(camera, LOW);
}

// the loop function runs over and over again forever
void loop() {

  declenchements();

}

void declenchements () {

  if (digitalRead(p5) == LOW) {
    digitalWrite(camera, HIGH);

    delay(5000); //5 second delay
    affiche(num++);
  }
  if (digitalRead(p10) == LOW) {
    digitalWrite(camera, HIGH);

    delay(10000); //10 second delay

    affiche(num++);
  }
  if (digitalRead(p20) == LOW) {
    digitalWrite(camera, HIGH);

    delay(20000); //20 second delay
    affiche(num++);
  }
  if (digitalRead(p30) == LOW) {
    digitalWrite(camera, HIGH);

    delay(30000); //30 second delay
    affiche(num++);
  }
  if (digitalRead(p60) == LOW) {
    digitalWrite(camera, HIGH);

    delay(60000); //60 second delay
    affiche(num++);
  }
  if (digitalRead(p90) == LOW) {
    digitalWrite(camera, HIGH);

    delay(90000); //90 second delay
    affiche(num++);
  }
  if (digitalRead(p120) == LOW) {
    digitalWrite(camera, HIGH);

    delay(120000); //120 second delay
    affiche(num++);
  }
  if (digitalRead(p150) == LOW) {
    digitalWrite(camera, HIGH);

    delay(150000); //150 second delay
    affiche(num++);
  }
  else {
    digitalWrite(camera, LOW);
  }
  delay(3000);

}

Après il faut savoir comment et quand remettre num à zéro.
Comme @terwal le demande, il faut donner des détails sur votre matériel.

moi je mettrais un encodeur rotatif avec bouton pour gérer le tout avec si on veut plus de sécurité un bouton pour le trigger. ça permettrait de régler plus finement la durée

bonjour
j'ai testé le deuxième code et ça marche impeccable
merci
cdt

Bonjour @astronomy
Tant mieux pour vous.

Bonne journée.