본문 바로가기
HW 프로그래밍/아두이노

TM 1637 2개 사용하기

by N2info 2018. 12. 21.

TM 1637 2개 사용하기


TM 1637 1개를 사용하는 것을 예제로 구현해 봤다.

그러나 실제는 1개로는 한계가 있다.


그래서 2개를 연결하는 방법을 찾아보았다.


참조 : https://forum.arduino.cc/index.php?topic=404178.0


생각보다는 간단하다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#include <Arduino.h>
#include <TM1637Display.h>
TM1637Display one(2,3);  //CLK = 2, DIO = 3
TM1637Display two(6,7);  //CLK = 4, DIO = 5
 
#define TEST_DELAY   200
 
const uint8_t SEG_DONE[] = {
  SEG_B | SEG_C | SEG_D | SEG_E | SEG_G,           // d
  SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F,   // O
  SEG_C | SEG_E | SEG_G,                           // n
  SEG_A | SEG_D | SEG_E | SEG_F | SEG_G            // E
  };
 
void setup()
{
  one.clear();
  one.setBrightness(0x0f);
  two.clear();
  two.setBrightness(0x0f);
}
 
void loop()
{
  int k;
  uint8_t data[] = { 0xff0xff0xff0xff };
  uint8_t blank[] = { 0x000x000x000x00 };
  
  // All segments on
  one.setSegments(data);
  delay(TEST_DELAY);
 
  two.setSegments(data);
  delay(TEST_DELAY);
 
  // Selectively set different digits
  data[0= one.encodeDigit(0);
  data[1= one.encodeDigit(1);
  data[2= one.encodeDigit(2);
  data[3= one.encodeDigit(3);
  one.setSegments(data);
  delay(TEST_DELAY);
 
  // Selectively set different digits
  data[0= two.encodeDigit(0);
  data[1= two.encodeDigit(1);
  data[2= two.encodeDigit(2);
  data[3= two.encodeDigit(3);
  two.setSegments(data);
  delay(TEST_DELAY);
 
  /*
  for(k = 3; k >= 0; k--) {
  display.setSegments(data, 1, k);
  delay(TEST_DELAY);
  }
  */
 
  one.clear();
  one.setSegments(data+222);
  delay(TEST_DELAY);
 
  two.clear();
  two.setSegments(data+222);
  delay(TEST_DELAY);
 
 
  one.clear();
  one.setSegments(data+221);
  delay(TEST_DELAY);
 
  two.clear();
  two.setSegments(data+221);
  delay(TEST_DELAY);
 
  one.clear();
  one.setSegments(data+131);
  delay(TEST_DELAY);
 
  two.clear();
  two.setSegments(data+131);
  delay(TEST_DELAY);
 
  // Show decimal numbers with/without leading zeros
  one.showNumberDec(0false); // Expect: ___0
  delay(TEST_DELAY);
  one.showNumberDec(0true);  // Expect: 0000
  delay(TEST_DELAY);
  one.showNumberDec(1false); // Expect: ___1
  delay(TEST_DELAY);
  one.showNumberDec(1true);  // Expect: 0001
  delay(TEST_DELAY);
  one.showNumberDec(301false); // Expect: _301
  delay(TEST_DELAY);
  one.showNumberDec(301true); // Expect: 0301
  delay(TEST_DELAY);
  one.clear();
  one.showNumberDec(14false21); // Expect: _14_
  delay(TEST_DELAY);
  one.clear();
  one.showNumberDec(4true22);  // Expect: 04__
  delay(TEST_DELAY);
  one.showNumberDec(-1false);  // Expect: __-1
  delay(TEST_DELAY);
  one.showNumberDec(-12);        // Expect: _-12
  delay(TEST_DELAY);
  one.showNumberDec(-999);       // Expect: -999
  delay(TEST_DELAY);
  one.clear();
  one.showNumberDec(-5false30); // Expect: _-5_
  delay(TEST_DELAY);
  one.showNumberHexEx(0xf1af);        // Expect: f1Af
  delay(TEST_DELAY);
  one.showNumberHexEx(0x2c);          // Expect: __2C
  delay(TEST_DELAY);
  one.showNumberHexEx(0xd10true); // Expect: 00d1
  delay(TEST_DELAY);
  one.clear();
  one.showNumberHexEx(0xd10true2); // Expect: d1__
  delay(TEST_DELAY);
 
  // Show decimal numbers with/without leading zeros
  two.showNumberDec(0false); // Expect: ___0
  delay(TEST_DELAY);
  two.showNumberDec(0true);  // Expect: 0000
  delay(TEST_DELAY);
  two.showNumberDec(1false); // Expect: ___1
  delay(TEST_DELAY);
  two.showNumberDec(1true);  // Expect: 0001
  delay(TEST_DELAY);
  two.showNumberDec(301false); // Expect: _301
  delay(TEST_DELAY);
  two.showNumberDec(301true); // Expect: 0301
  delay(TEST_DELAY);
  two.clear();
  two.showNumberDec(14false21); // Expect: _14_
  delay(TEST_DELAY);
  two.clear();
  two.showNumberDec(4true22);  // Expect: 04__
  delay(TEST_DELAY);
  two.showNumberDec(-1false);  // Expect: __-1
  delay(TEST_DELAY);
  two.showNumberDec(-12);        // Expect: _-12
  delay(TEST_DELAY);
  two.showNumberDec(-999);       // Expect: -999
  delay(TEST_DELAY);
  two.clear();
  two.showNumberDec(-5false30); // Expect: _-5_
  delay(TEST_DELAY);
  two.showNumberHexEx(0xf1af);        // Expect: f1Af
  delay(TEST_DELAY);
  two.showNumberHexEx(0x2c);          // Expect: __2C
  delay(TEST_DELAY);
  two.showNumberHexEx(0xd10true); // Expect: 00d1
  delay(TEST_DELAY);
  two.clear();
  two.showNumberHexEx(0xd10true2); // Expect: d1__
  delay(TEST_DELAY);
  
  // Run through all the dots
  for(k=0; k <= 4; k++) {
    one.showNumberDecEx(0, (0x80 >> k), true);
    delay(TEST_DELAY);
  }
 
  // Run through all the dots
  for(k=0; k <= 4; k++) {
    two.showNumberDecEx(0, (0x80 >> k), true);
    delay(TEST_DELAY);
  }
 
  // Brightness Test
  for(k = 0; k < 4; k++)
  data[k] = 0xff;
  for(k = 0; k < 7; k++) {
    one.setBrightness(k);
    one.setSegments(data);
    delay(TEST_DELAY);
  }
 
  // Brightness Test
  for(k = 0; k < 4; k++)
  data[k] = 0xff;
  for(k = 0; k < 7; k++) {
    two.setBrightness(k);
    two.setSegments(data);
    delay(TEST_DELAY);
  }
  
  // On/Off test
  for(k = 0; k < 4; k++) {
    one.setBrightness(7false);  // Turn off
    one.setSegments(data);
    delay(TEST_DELAY);
    one.setBrightness(7true); // Turn on
    one.setSegments(data);
    delay(TEST_DELAY);  
  }
 
  // On/Off test
  for(k = 0; k < 4; k++) {
    two.setBrightness(7false);  // Turn off
    two.setSegments(data);
    delay(TEST_DELAY);
    two.setBrightness(7true); // Turn on
    two.setSegments(data);
    delay(TEST_DELAY);  
  }
 
 
  // Done!
  one.setSegments(SEG_DONE);
 
  // Done!
  two.setSegments(SEG_DONE);
 
  //while(0);
}
cs


작동 동영상은 아래와 같다.