Other Arduino Codes and Videos by Robojax

How to use TM1638 4 digit display. Watch video

دروس آردوینو به فارسی

This is the Arduino code for TM1638 8 digits display with 4x4 Matrix Buttons

This video shows you how to use TM1638 8 digit 7-segment display module for arduino. http://robojax.com/learn/arduino/
  1. download TM1648 Manual
  2. TM1638 Library (from Robojax.com)
  3. TM1638 Library (from GetHub)

 /*
 * This is the Arduino code for TM1638 8 digits display.
 * with 16 matrix buttons.
 *  * 
 * Written by Ahmad Nejrabi for Robojax Video
 * Date: Dec 10, 2017, in Ajax, Ontario, Canada
 * Permission granted to share this code given that this
 * note is kept with the code.
 * Disclaimer: this code is "AS IS" and for educational purpose only.
 * 
 */

/*
// http://arduinolearning.com/code/qyf-tm1638-and-arduino-module.php#codesyntax_2
 * Modified for Robojax video on Dec 10, 2017

 */


#include <TM1638.h>
#include <TM1638QYF.h>

#define STB 5
#define DIO 3
#define CLK 2
 
TM1638QYF module(DIO, CLK, STB);
word mode;
 
 
void setup() 
{
  module.setupDisplay(true, 7);
  mode = 0;//initial button zero 
}
 
void update(TM1638QYF* module, word* mode) {
  word buttons = module->getButtons();
 
  // button pressed - change mode
  if (buttons != 0) {
    *mode = buttons >> 1;
 
    if (*mode < 0) {
      module->clearDisplay();
      delay(100);
    }
  }
 
  switch (*mode) {
    case 0://S1
      module->setDisplayToString("press 1");
      break;
    case 1://S2
      module->setDisplayToString("press 2");
      break;  
    case 2://S3
      module->setDisplayToString("press 3");
      break;
    case 4://S4
      module->setDisplayToString("press 4");
      break;
    case 8://S5
      module->setDisplayToString("press 5");
      break;
    case 16://S6
      module->setDisplayToString("press 6");
      break;
    case 32://S7
      module->setDisplayToString("press 7");
      break;
    case 64://S8
      module->setDisplayToString("press 8");
      break;
    case 128://S9
      module->setDisplayToString("press 9");
      break;
    case 256://S10
      module->setDisplayToString("press 10");
      break;
    case 512://S11
      module->setDisplayToString("press 11");
      break;
    case 1024://S12
      module->setDisplayToString("press 12");
      break;
    case 2048://S13
      module->setDisplayToString("press 13");
      break;
    case 4096://S14
      module->setDisplayToString("press 14");
      break;
    case 8192://S15
      module->setDisplayToString("press 15");
      break;
    case 16384://S16
      module->setDisplayToString("robojax");
      break;
    default:// unknown busson
      module->setDisplayToString("?????");
      break;
  }
}
 
void loop() 
{
  update(&module, &mode);
}
   

If you found this tutorial helpful, please support me so I can continue creating content like this. support me via PayPal