-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCosaTM1637_test.ino
150 lines (131 loc) · 3.58 KB
/
CosaTM1637_test.ino
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
/**
* @file CosaTM1637_test.ino
* @version 1.0
*
* @section License
* Copyright (C) 2014-2015, jeditekunum
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*/
#include "Cosa/UART.hh"
#include "Cosa/Trace.hh"
#include "Cosa/OutputPin.hh"
#include "TM1637.hh"
#define PAUSE 500 // ms
#define STEP(x) {x; delay(PAUSE);}
TM1637 tm1637(Board::D20, Board::D21);
void setup()
{
uart.begin(9600);
trace.begin(&uart, PSTR("CosaTM1637_test: started"));
}
void loop()
{
uint8_t data[] = { 0xff, 0xff, 0xff, 0xff};
uint8_t i;
// All on/off
STEP(tm1637.set(data));
STEP(tm1637.clear());
STEP(tm1637.set(data));
STEP(tm1637.clear());
// Colon
data[0] = 0;
data[1] = 0;
data[2] = 0;
data[3] = 0;
for (i=0; i<4; i++)
{
tm1637.colon(!tm1637.colon());
STEP(tm1637.set(data));
}
STEP(tm1637.clear());
// Walking
data[0] = tm1637.encode(0);
for (i=0; i<4; i++)
{
STEP(tm1637.set(data, 1, i));
tm1637.clear();
}
for (i=0; i<3; i++)
{
STEP(tm1637.set(data, 1, 2-i));
tm1637.clear();
}
// Pretty patterns
data[0] = TM1637::SEG_F | TM1637::SEG_E | TM1637::SEG_B | TM1637::SEG_C;
for (i=0; i<4; i++)
STEP(tm1637.set(data, 1, i));
STEP(tm1637.clear());
data[0] = TM1637::SEG_A | TM1637::SEG_G | TM1637::SEG_D;
for (i=0; i<4; i++)
STEP(tm1637.set(data, 1, i));
STEP(tm1637.clear());
data[0] = TM1637::SEG_F | TM1637::SEG_G | TM1637::SEG_C;
for (i=0; i<4; i++)
STEP(tm1637.set(data, 1, i));
STEP(tm1637.clear());
data[0] = TM1637::SEG_B | TM1637::SEG_G | TM1637::SEG_E;
for (i=0; i<4; i++)
STEP(tm1637.set(data, 1, i));
STEP(tm1637.clear());
// Box
data[0] = TM1637::SEG_A | TM1637::SEG_D | TM1637::SEG_F | TM1637::SEG_E;
data[1] = TM1637::SEG_A | TM1637::SEG_D;
data[2] = TM1637::SEG_A | TM1637::SEG_D;
data[3] = TM1637::SEG_A | TM1637::SEG_D | TM1637::SEG_B | TM1637::SEG_C;
STEP(tm1637.set(data));
tm1637.colon(true);
STEP(tm1637.set(data));
tm1637.colon(false);
STEP(tm1637.clear());
// Line
data[0] = TM1637::SEG_G;
for (i=0; i<4; i++)
STEP(tm1637.set(data, 1, i));
STEP(tm1637.clear());
// Step
data[0] = TM1637::SEG_D;
data[1] = TM1637::SEG_G;
data[2] = TM1637::SEG_A;
data[3] = TM1637::SEG_C;
for (i=0; i<4; i++)
STEP(tm1637.set(&data[i], 1, i));
STEP(tm1637.clear());
// Basic numbers with leading zeros
for (i=0; i<10; i++)
STEP(tm1637.show(i, true));
STEP(tm1637.clear());
// Hex
for (i=0; i<16; i++)
STEP(tm1637.show(i, false, 16));
STEP(tm1637.clear());
// Binary
for (i=0; i<8; i++)
STEP(tm1637.show(i, false, 2));
STEP(tm1637.clear());
// Brightness Test
uint8_t before = tm1637.brightness();
for(i=TM1637::DIM; i<=TM1637::BRIGHT; i++)
{
tm1637.brightness(i);
STEP(tm1637.show(i, true));
}
tm1637.brightness(before);
STEP(tm1637.clear());
// Colon
for (i=0; i<10; i++)
{
tm1637.colon(!tm1637.colon());
STEP(tm1637.show(2400 + i));
}
STEP(tm1637.clear());
}