BrickUp API Service for Docker version.

TM1637.h 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * TM1637.h
  3. * A library for the 4 digit display
  4. *
  5. * Copyright (c) 2012 seeed technology inc.
  6. * Website : www.seeed.cc
  7. * Author : Frankie.Chu
  8. * Create Time: 9 April,2012
  9. * Change Log :
  10. *
  11. * The MIT License (MIT)
  12. *
  13. * Permission is hereby granted, free of charge, to any person obtaining a copy
  14. * of this software and associated documentation files (the "Software"), to deal
  15. * in the Software without restriction, including without limitation the rights
  16. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  17. * copies of the Software, and to permit persons to whom the Software is
  18. * furnished to do so, subject to the following conditions:
  19. *
  20. * The above copyright notice and this permission notice shall be included in
  21. * all copies or substantial portions of the Software.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  24. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  25. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  26. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  27. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  28. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  29. * THE SOFTWARE.
  30. */
  31. #ifndef TM1637_h
  32. #define TM1637_h
  33. #include <inttypes.h>
  34. #include <Arduino.h>
  35. //************definitions for TM1637*********************
  36. #define ADDR_AUTO 0x40
  37. #define ADDR_FIXED 0x44
  38. #define STARTADDR 0xc0
  39. /**** definitions for the clock point of the digit tube *******/
  40. #define POINT_ON 1
  41. #define POINT_OFF 0
  42. /**************definitions for brightness***********************/
  43. #define BRIGHT_DARKEST 0
  44. #define BRIGHT_TYPICAL 2
  45. #define BRIGHTEST 7
  46. class TM1637
  47. {
  48. public: // api for graphical programming project - loovee@2015-8-4
  49. TM1637(){set(BRIGHTEST);}
  50. /*
  51. * Function Name: DigitDisplayWrite
  52. * Input - pinClk, pin of clock
  53. * pinDta, pin of data
  54. * num, number to display, should be between 0-9999
  55. * Return - NULL
  56. */
  57. void DigitDisplayWrite(int pinClk, int pinDta, int num)
  58. {
  59. if(num>9999 || num<0)return;
  60. static int num_buf = 0;
  61. if(num == num_buf)return;
  62. num_buf = num;
  63. // init io
  64. Clkpin = pinClk;
  65. Datapin = pinDta;
  66. pinMode(Clkpin, OUTPUT);
  67. pinMode(Datapin, OUTPUT);
  68. if(num<10)
  69. {
  70. display(3, num);
  71. display(2, 0x7f);
  72. display(1, 0x7f);
  73. display(0, 0x7f);
  74. }
  75. else if(num<100)
  76. {
  77. display(3, num%10);
  78. display(2, (num/10)%10);
  79. display(1, 0x7f);
  80. display(0, 0x7f);
  81. }
  82. else if(num<1000)
  83. {
  84. display(3, num%10);
  85. display(2, (num/10)%10);
  86. display(1, (num/100)%10);
  87. display(0, 0x7f);
  88. }
  89. else
  90. {
  91. display(3, num%10);
  92. display(2, (num/10)%10);
  93. display(1, (num/100)%10);
  94. display(0, (num/1000)%10);
  95. }
  96. }
  97. public:
  98. TM1637(uint8_t, uint8_t);
  99. void init(void); //To clear the display
  100. void display(int8_t DispData[]);
  101. void display(uint8_t BitAddr,int8_t DispData);
  102. void clearDisplay(void);
  103. void set(uint8_t = BRIGHT_TYPICAL,uint8_t = 0x40,uint8_t = 0xc0);//To take effect the next time it displays.
  104. void point(boolean PointFlag);//whether to light the clock point ":".To take effect the next time it displays.
  105. private:
  106. uint8_t Clkpin;
  107. uint8_t Datapin;
  108. uint8_t Cmd_SetData;
  109. uint8_t Cmd_SetAddr;
  110. uint8_t Cmd_DispCtrl;
  111. boolean _PointFlag; //_PointFlag=1:the clock point on
  112. private:
  113. int writeByte(int8_t wr_data);//write 8bit data to tm1637
  114. void start(void);//send start bits
  115. void stop(void); //send stop bits
  116. void coding(int8_t DispData[]);
  117. int8_t coding(int8_t DispData);
  118. void bitDelay(void);
  119. };
  120. #endif