Advertisement
Guest User

Untitled

a guest
Jan 13th, 2022
26
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Library examples for TM1638.
  3.  
  4. Copyright (C) 2011 Ricardo Batista <rjbatista at gmail dot com>
  5.  
  6. This program is free software: you can redistribute it and/or modify
  7. it under the terms of the version 3 GNU General Public License as
  8. published by the Free Software Foundation.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17. */
  18.  
  19. #include <TM1638.h>
  20. #include <TM1638QYF.h>
  21.  
  22. TM1638QYF module(3, 2, 5);
  23. word mode;
  24.  
  25. unsigned long startTime;
  26.  
  27. void setup() {
  28.   startTime = millis();
  29.  
  30.   module.setupDisplay(true, 1);
  31.   mode = 0;
  32. }
  33.  
  34. void update(TM1638QYF* module, word* mode) {
  35.   word buttons = module->getButtons();
  36.   unsigned long runningSecs = (millis() - startTime) / 1000;
  37.  
  38.   // button pressed - change mode
  39.   if (buttons != 0) {
  40.     *mode = buttons >> 1;
  41.  
  42.     if (*mode < 128) {
  43.       module->clearDisplay();
  44.       delay(100);
  45.     }
  46.   }
  47.  
  48.   switch (*mode) {
  49.     case 0:
  50.       module->setDisplayToDecNumber(runningSecs, 1 << 6);
  51.       break;
  52.     case 1:
  53.       module->setDisplayToDecNumber(runningSecs, 1 << 5, false);
  54.       break;
  55.     case 2:
  56.       module->setDisplayToHexNumber(runningSecs, 1 << 4);
  57.       break;
  58.     case 4:
  59.       module->setDisplayToHexNumber(runningSecs, 1 << 3, false);
  60.       break;
  61.     case 8:
  62.       module->setDisplayToBinNumber(runningSecs, 1 << 2);
  63.       break;
  64.     case 16:
  65.       char s[9];
  66.       sprintf(s, "Secs %03d", runningSecs % 999);
  67.       module->setDisplayToString(s, 1 << 1);
  68.       break;
  69.     case 32:
  70.       if (runningSecs % 2 == 0) {
  71.         module->setDisplayToString("TM1638QY", 1);
  72.       } else {
  73.         module->setDisplayToString(String("LIBRARY "), 1);
  74.       }
  75.  
  76.       break;
  77.     case 64:
  78.       module->setDisplayToError();
  79.       break;
  80.     case 128:
  81.       module->setDisplayToDecNumber(*mode, 0);
  82.       break;
  83.     case 256:
  84.       module->setDisplayToString("ABCDE", 1 << (runningSecs % 8));
  85.       break;
  86.     default:
  87.       module->setDisplayToBinNumber(buttons & 0xF, buttons >> 8);
  88.   }
  89. }
  90.  
  91. void loop() {
  92.   update(&module, &mode);
  93. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement