-
Notifications
You must be signed in to change notification settings - Fork 0
/
S_Seg.h
124 lines (108 loc) · 3.34 KB
/
S_Seg.h
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
/*************************************************************
author: <Yuri Costa (yurioor@hotmail.com)>
description: <Simple 7-segment LED object>
ports = { a, b, c, d, e, f, g, (dot), (Vcc or GND) };
type = ANODE;// = CATHODE;
S_Seg mS_Seg = new S_Seg(int* ports, type);
create your LED 7-segment and turn it on.
mS_Seg->turn(ON); //turn off with OFF argument
Change it's displaying value
mS_Seg->hex_to_7seg(16); //15, 14, 13... 0
Dot modifier function not implemented yet.
*************************************************************/
#define ANODE 1
#define CATHODE 0
#define ON 1
#define OFF 0
int table[2][16][7] =
{
{
{HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, LOW },
{LOW, HIGH, HIGH, LOW, LOW, LOW, LOW},
{HIGH, HIGH, LOW, HIGH, HIGH, LOW, HIGH },
{HIGH, HIGH, HIGH, HIGH, LOW, LOW, HIGH },
{LOW, HIGH, HIGH, LOW, LOW, HIGH, HIGH },
{HIGH, LOW, HIGH, HIGH, LOW, HIGH, HIGH },
{HIGH, LOW, HIGH, HIGH, HIGH, HIGH, HIGH },
{HIGH, HIGH, HIGH, LOW, LOW, LOW, LOW },
{HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH },
{HIGH, HIGH, HIGH, HIGH, LOW, HIGH, HIGH },
{HIGH, HIGH, HIGH, LOW, HIGH, HIGH, HIGH },
{LOW, LOW, HIGH, HIGH, HIGH, HIGH, HIGH },
{HIGH, LOW, LOW, HIGH, HIGH, HIGH, LOW },
{LOW, HIGH, HIGH, HIGH, HIGH, LOW, HIGH },
{HIGH, LOW, LOW, HIGH, HIGH, HIGH, HIGH },
{HIGH, LOW, LOW, LOW, HIGH, HIGH, HIGH }
},
{
{LOW, LOW, LOW, LOW, LOW, LOW, HIGH,},
{HIGH, LOW, LOW, HIGH, HIGH, HIGH, HIGH },
{LOW, LOW, HIGH, LOW, LOW, HIGH, LOW},
{LOW, LOW, LOW, LOW, HIGH, HIGH, LOW },
{HIGH, LOW, LOW, HIGH, HIGH, LOW, LOW },
{LOW, HIGH, LOW, LOW, HIGH, LOW, LOW },
{LOW, HIGH, LOW, LOW, LOW, LOW, LOW },
{LOW, LOW, LOW, HIGH, HIGH, HIGH, HIGH },
{LOW, LOW, LOW, LOW, LOW, LOW, LOW },
{LOW, LOW, LOW, LOW, HIGH, LOW, LOW },
{LOW, LOW, LOW, HIGH, LOW, LOW, LOW },
{HIGH, HIGH, LOW, LOW, LOW, LOW, LOW },
{LOW, HIGH, HIGH, LOW, LOW, LOW, HIGH },
{HIGH, LOW, LOW, LOW, LOW, HIGH, LOW },
{LOW, HIGH, HIGH, LOW, LOW, LOW, LOW },
{LOW, HIGH, HIGH, HIGH, LOW, LOW, LOW }
}
};
class S_Seg
{
protected:
int mode;
private:
int* led;
public:
////led[9] = { a, b, c, d, e, f, g, (dot), (Vcc or GND) };
S_Seg (int* _led, int _mode)
{
mode = _mode;
led = _led;
int i;
for(i = 0; i < 9; i++)
{
pinMode( led[ i ], OUTPUT);
}
}
S_Seg(){}
void hex_to_7seg(int hex )
{
int i ;
for(i = 0; i <7; i++)
{
digitalWrite( led[ i ], table[mode][hex][ i ] );
}
}
void turn(int on_off)
{
if(on_off == ON )
{
if(mode == ANODE)
{
digitalWrite(led[8], HIGH);
}
else
{
digitalWrite(led[8], LOW);
}
}
else
{
if(mode == ANODE)
{
digitalWrite(led[8], LOW);
}
else
{
digitalWrite(led[8], HIGH);
}
}
}
};