Arduino wih TM1638

I like to use my own button with TM1638 and not the buttons on the TM1638.
I use arduino uno.

I've tried the tutorial button but that did not work.
I like to combine it with the following code (attachment).
Can someone help me out?

Regards Ad

iracingsli_voor2.ino (3.6 KB)

(deleted)

The TM1638 chip supports button switches. The TM1638 library has button support. What do you mean "your own button"? Is it attached to the TM1638 or not? In future, please post your code inside code tags, like this:

#include <TM1638.h>

TM1638 module1(8, 7, 9);
TM1638 module2(8, 6, 9);

word leds [17] = {0, 256, 768, 1792, 3840, 7936, 16128, 32512, 65280, 1, 3, 7, 15, 31, 63, 127, 255};

byte buttons, oldbuttons, page;
byte gear, spd, shift, rpm_h, rpm_l, engine;
int fuel;
word rpm;
boolean changed, blinkrpm;
unsigned long milstart, milstart2 = 0;

void setup() {
  Serial.begin(9600);

  oldbuttons = 0;
  page = 0;
  changed = false;
  blinkrpm = false;
}

void loop() {
  if (Serial.available() > 0) {
    if (Serial.available() > 8) {
      if (Serial.read() == 255) {
        gear = Serial.read();
        spd = Serial.read();
        rpm_h = Serial.read();
        rpm_l = Serial.read();
        fuel = Serial.read();
        shift = Serial.read();
        engine = Serial.read();

        rpm = (rpm_h << 8) | rpm_l;
      }
    }
  }

  buttons = module1.getButtons();
  if (buttons != 0) {
    if (buttons != oldbuttons) {
      oldbuttons = buttons;
      page = buttons;
      module1.clearDisplay();
      module2.clearDisplay();

      switch (page) {
        case 8:
          module2.setDisplayToString("Gear spd", 0, 0);
          break;
        case 16:
          module2.setDisplayToString("Engine", 0, 0);
          break;
        case 32:
          module2.setDisplayToString("Fuel pct", 0, 0);
          break;
      }

      changed = true;
      milstart = millis();
    }
  }

  if (changed == false) {
    switch (page) {
      case 8:
        if (gear == 0)
          module1.setDisplayToString("r", 0, 0);
        else if (gear == 1)
          module1.setDisplayToString("n", 0, 0);
        else
          module1.setDisplayToString(String(gear - 1, DEC), 0, 0);

        if (spd < 100)
          module1.clearDisplayDigit(7, false);
        module1.setDisplayToString(String(spd, DEC), 0, 5);
        break;
      case 16:
        module1.setDisplayToDecNumber(rpm, 0, false);
        break;
      case 32:
        String fuelstr = String(fuel, DEC);
        module1.setDisplayToString(String(fuelstr + " pct"), 0, 0);
        break;
    }
  } else {
    if ((millis() - milstart) > 2000) {
      changed = false;
      module1.clearDisplay();
    }
  }

  if ((engine & 0x10) == 0) {
    if (shift == 16) {
      if ((millis() - milstart2) > 50) {
        if (blinkrpm == false) {
          module1.setLEDs(0x0000);
          blinkrpm = true;
        } else {
          module1.setLEDs(leds[shift]);
          blinkrpm = false;
        }
        milstart2 = millis();
      }
    } else {
      module1.setLEDs(leds[shift]);
    }
  } else {
    if ((millis() - milstart2) > 200) {
      if (blinkrpm == false) {
        module1.setLEDs(0x0000);
        blinkrpm = true;
      } else {
        module1.setLEDs(0xFF00);
        blinkrpm = false;
      }
      milstart2 = millis();
    }
  }
}

(deleted)

I try to explain what I mean.

I'm making a button box.
I got a TM1638 and yes there are pushbuttons on it.
I want to use a button on that buttonbox to control the TM1638
But I don't know how to program that.

Regards Ad

(deleted)

adjet:
I try to explain what I mean.

I'm making a button box.
I got a TM1638 and yes there are pushbuttons on it.
I want to use a button on that buttonbox to control the TM1638
But I don't know how to program that.

Regards Ad

Your code already collects button data from the module. So I must assume that you are only copy and pasting and not programming. It is impossible to do what you are trying to do without some understanding of what you are doing. You can get that by looking at the example sketches that come with the TM1638 library that you are using. Not copy and pasting, reading and understanding.

I know this because I did exactly that with exactly the same module. It was one of my first projects. If you can't get the example sketches working, then you have a hardware problem and we might be able to help you with that.

You mentioned "tutorial". Generally those are written by people who know even less than you do. Go to the original sources for information.

L.s,

The code as is, is working fine.
The buttons on the tm 1638 are working fine.
Every example sketch is working fine with me.

I only want to replace the use of a button on the tm1638 with a button on my buttonbox (using the arduino uno also used in the examples).

Ad

(deleted)

I am not disrespecting spycather2.
But some thinking that I did not had the examples working.
So I explained that i have the tm1638 board running all the examples with the arduino uno.

That works fine.

I only want to use another button without taking a button out of the tm1638.
I think that must be possible by programming it.

What is wrong with that question (beside my knowledge)

Regards Ad

adjet:
I only want to use another button without taking a button out of the tm1638.
I think that must be possible by programming it.

What is wrong with that question (beside my knowledge)

You haven't done a good job of explaining it. For example, you said,

I want to use a button on that buttonbox to control the TM1638

which is in direct contradiction to what you are now telling us. Do you want to attach a button switch to one of the digital inputs of the Arduino? It is one of the most common Arduino functions, and there are example sketches with the IDE, as well as millions of other examples and tutorials online.

Look at "button.ino" that ships with the IDE.

I do not understand what you are saying.

  1. I have a TM1638 board working with an arduino uno.

  2. I making a buttonbox and want to use one of those buttons in stead of the ones on the TM1638.

I do not see any contradiction.

I can make a button work like in button.ino
I don't know how to program that in the program I use
You are saying there are over a million examples.
I have not find one.
I only need one.
Yes I want to learn.
But I need an example.

Ad

If you wire the box button parallel to the button on the TM1638 shield it should work just like the
button on the shield. You have an example for that.

You can not move buttons with software.

You can wire the box button like a normal button and execute the same functionality when it is pressed,
as you would if the TM1628 buton was pressed.

What else do you need?

Besides picking one of the possibilities...

The TM1638 datasheet has examples of switch wiring.