Modify a code for a different type of 7 segments display

Is it possible to change this code to be used with a TM1637 7 segment display if i don't have an adafruit display? Thank you

#include <Wire.h> // Enable this line if using Arduino Uno, Mega, etc.
#include <Adafruit_GFX.h>
#include "Adafruit_LEDBackpack.h"

Adafruit_7segment matrix = Adafruit_7segment();

bool clockRunning=false;
bool solved=false;
const int pinSwitch1 = 7; //Pin Reed
const int pinSwitch2 = 8; //Pin Reed
const int pinSwitch3 = 9; //Pin Reed
const int pinSwitch4 = 12; //Pin Reed
int switch1 = 0;
int switch2 = 0;
int switch3 = 0;
int switch4 = 0;
const int lockCode = 201;
uint16_t counter = 5000;
int countdownSpeed = 10;
void setup() {
#ifndef __AVR_ATtiny85__
  Serial.begin(9600);
  Serial.println("7 Segment Backpack Test");
#endif

  pinMode(pinSwitch1, INPUT);
  pinMode(pinSwitch2, INPUT);
  pinMode(pinSwitch3, INPUT);
  pinMode(pinSwitch4, INPUT);

  matrix.begin(0x70);
      // print a hex number
  
          matrix.print(0x3333,HEX);
          matrix.writeDisplay();
          delay(100);
          
          matrix.print(0x2222,HEX);
          matrix.writeDisplay();
          delay(100);
    
          matrix.print(0x1111,HEX);
          matrix.writeDisplay();
          delay(100);
 
    
    matrix.clear();
    matrix.writeDisplay();
    delay(500);
    Serial.println("READY!"); 
}

void loop() {
  if(solved == false){
    switch1 = digitalRead(pinSwitch1);
    switch2 = digitalRead(pinSwitch2); 
    switch3 = digitalRead(pinSwitch3);
    switch4 = digitalRead(pinSwitch4); 

    if (switch1 == HIGH && clockRunning==false)
    {
      Serial.println("BEGIN!"); 
      clockRunning = true;
    }
       
     if(clockRunning==true){
        matrix.println(counter);
        matrix.writeDigitRaw(2,0x02);
        matrix.writeDisplay();
        delay(countdownSpeed);
                
        if(counter == 0){
          matrix.print(0xDEAD, HEX);
          matrix.writeDisplay();
          Serial.println("BOOM!"); 
          solved = true; 
        } else {
          counter--;
        }
      }
    
      if(switch1 == HIGH && switch2 == HIGH && switch3 == HIGH && switch4 == HIGH && clockRunning==true){
        //SOLVED!
        solved=1;
        Serial.println("solved");
        clockRunning = false;
        for (uint16_t counter = 4; counter > 0; counter--) {
          matrix.print(0x0000,HEX);
          matrix.writeDisplay();
          delay(750);
          matrix.clear();
          matrix.writeDisplay();
          delay(750);
        }
        

        matrix.println(lockCode);
        matrix.writeDisplay();
        
      }
  }
 
}

Why not use the TM1637 library?

Can you guide me please?? What lines should i change?

Take a look here: Arduino Playground - TM1637
The library includes an example.

I tried, but i have an error code with "matrix" line.

Hard to tell without seeing what you "tried", or the actual error message.

Did you try the example code that comes with the library? Did it work?

I replace the library, but i need to define MATRIX on my coding, i'm all mixed up :frowning:

#include "SevenSegmentTM1637.h"
#include "SevenSegmentFun.h"

const byte CLK=2; //CLK display
const byte DIO=3; //DIO display

bool clockRunning=false;
bool solved=false;
const int pinSwitch1 = 7; //Pin Reed
const int pinSwitch2 = 8; //Pin Reed
const int pinSwitch3 = 9; //Pin Reed
const int pinSwitch4 = 12; //Pin Reed
int switch1 = 0;
int switch2 = 0;
int switch3 = 0;
int switch4 = 0;
const int lockCode = 201;
uint16_t counter = 5000;
int countdownSpeed = 10;
void setup() {
#ifndef __AVR_ATtiny85__
  Serial.begin(9600);
  Serial.println("7 Segment Backpack Test");
#endif

  pinMode(pinSwitch1, INPUT);
  pinMode(pinSwitch2, INPUT);
  pinMode(pinSwitch3, INPUT);
  pinMode(pinSwitch4, INPUT);

  matrix.begin(0x73);
      // print a hex number
  
          matrix.print(0x3333,HEX);
          matrix.writeDisplay();
          delay(100);
          
          matrix.print(0x2222,HEX);
          matrix.writeDisplay();
          delay(100);
    
          matrix.print(0x1111,HEX);
          matrix.writeDisplay();
          delay(100);
 
    
    matrix.clear();
    matrix.writeDisplay();
    delay(500);
    Serial.println("READY!"); 
}

void loop() {
  if(solved == false){
    switch1 = digitalRead(pinSwitch1);
    switch2 = digitalRead(pinSwitch2); 
    switch3 = digitalRead(pinSwitch3);
    switch4 = digitalRead(pinSwitch4); 

    if (switch1 == HIGH && clockRunning==false)
    {
      Serial.println("BEGIN!"); 
      clockRunning = true;
    }
       
     if(clockRunning==true){
        matrix.println(counter);
        matrix.writeDigitRaw(2,0x02);
        matrix.writeDisplay();
        delay(countdownSpeed);
                
        if(counter == 0){
          matrix.print(0xDEAD, HEX);
          matrix.writeDisplay();
          Serial.println("BOOM!"); 
          solved = true; 
        } else {
          counter--;
        }
      }
    
      if(switch1 == HIGH && switch2 == HIGH && switch3 == HIGH && switch4 == HIGH && clockRunning==true){
        //SOLVED!
        solved=1;
        Serial.println("solved");
        clockRunning = false;
        for (uint16_t counter = 4; counter > 0; counter--) {
          matrix.print(0x0000,HEX);
          matrix.writeDisplay();
          delay(750);
          matrix.clear();
          matrix.writeDisplay();
          delay(750);
        }
        

        matrix.println(lockCode);
        matrix.writeDisplay();
        
      }
  }
 
}

gfvalvo:
Did you try the example code that comes with the library? Did it work?

You need to get rid of 'matrix' which used the old library and use the features of the new library instead.

Comment out all of the lines that use 'matrix'. Get the code to compile without any use of 'matrix'.

Now look at the lines that you commented out. What are they doing? Looks like most of them are calls to 'writeDisplay()'. Figure out what that did on the 'matrix' display and figure out how to do the equivalent thing using the new library. Put in the substitute lines.

Repeat with the less frequently used features of the 'matrix' object.

Eventually you will have the code doing what it used to do on the 'matrix' object but using the new library.

Ok i think i have to replace them by "display.", but i'm confused...

elbico:
Ok i think i have to replace them by "display.", but i'm confused...

So you should read the library documentation, the example sketches that came with the libraries, or the library source code until you are no longer confused.

Looks to me like an attempt at copy / paste programming. That rarely works out well.

it's a code by adafruit, but i want the same result puzzle with another display.

elbico:
it's a code by adafruit, but i want the same result puzzle with another display.

Then you have to understand how the original code works, how the library for the new display works, and how to modify the former to work with the latter. There are no shortcuts.

I try to program it all day long... no success at all. :frowning:

elbico:
I try to program it all day long... no success at all. :frowning:

Without any additional information like; what you did, what the code looks like, what doesn't work, error messages, etc. it'll be next to impossible for anyone to offer anything constructive.

The only way you're going to get help from the forum is to post the code that you've tried, describe exactly what you want the code to do, and describe exactly how what it actually does differs from what you want.

i'm gonna do some more research about it and i'll be back with it soon :wink: (sorry for my english, it's not my first language)