-
Notifications
You must be signed in to change notification settings - Fork 0
/
charlie.cpp
executable file
·122 lines (96 loc) · 2.12 KB
/
charlie.cpp
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
/*
* CharliePlexing Experiments
*/
int set[26][8] =
{
{ 0,1,2,2,2,2,2,2 },
{ 1,0,2,2,2,2,2,2 },
{ 2,1,0,2,2,2,2,2 },
{ 2,0,1,2,2,2,2,2 },
{ 2,2,1,0,2,2,2,2 },
{ 2,2,0,1,2,2,2,2 },
{ 2,2,2,1,0,2,2,2 },
{ 2,2,2,0,1,2,2,2 },
{ 2,2,2,2,0,1,2,2 },
{ 2,2,2,2,1,0,2,2 },
{ 2,2,2,2,2,0,1,2 },
{ 2,2,2,2,2,1,0,2 },
{ 2,2,2,2,2,2,1,0 },
{ 2,2,2,2,2,2,0,1 },
{ 1,2,0,2,2,2,2,2 },
{ 0,2,1,2,2,2,2,2 },
{ 2,1,2,0,2,2,2,2 },
{ 2,0,2,1,2,2,2,2 },
{ 2,2,1,2,0,2,2,2 },
{ 2,2,0,2,1,2,2,2 },
{ 2,2,2,1,2,0,2,2 },
{ 2,2,2,0,2,1,2,2 },
{ 2,2,2,2,1,2,0,2 },
{ 2,2,2,2,0,2,1,2 },
{ 2,2,2,2,2,1,2,0 },
{ 2,2,2,2,2,0,2,1 }
};
int mode[] = { OUTPUT, OUTPUT, INPUT };
int value[] = { 0, 1, 0 };
void led(int i, int ms);
void setup()
{
Serial.begin(115200);
}
// Nearly all of the pins are high or input/high all the time.
// Only one pin is zero at a time, to turn on a particular LED.
// If we do all the setup before setting this pin low, then
// immediately set this pin high again. We can get an isolated
// single LED on-at-a-time in a perfectly controlled way.
//
// This is important for the multiplexed reflective-IR sensor.
//
void loop()
{
int i,j;
for (i=0; i<9; i++) // FOR TEN SETTINGS
{
int lowpin, lowset;
for (j=0; j<9; j++) // EIGHT PINS 2-10
{
int n = set[i][j];
if (n == 0) lowpin = j+2;
else
{
pinMode(j+2, mode[n]);
digitalWrite(j+2, value[n]);
}
Serial.print(j);Serial.print(" ");
}
Serial.println();
// Now light the LED for one second.
pinMode(lowpin, OUTPUT);
digitalWrite(lowpin, 0);
delay(1000);
pinMode(lowpin, INPUT);
// Then pause for two seconds
delay(2000);
}
for (i=0; i<10; i++) // FOR TEN SETTINGS
{
led(i,100);
}
}
void led(int i, int ms)
{
int j, lowpin;
for (j=0; j<9; j++) // EIGHT PINS 2-10
{
int n = set[i][j];
if (n == 0) lowpin = j+2;
else
{
pinMode(j+2, mode[n]);
digitalWrite(j+2, value[n]);
}
}
pinMode(lowpin, OUTPUT);
digitalWrite(lowpin, 0);
delay(ms);
pinMode(lowpin, INPUT);
}