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