/
ArduinoSoftwareFinal.ino
161 lines (145 loc) · 18 KB
/
ArduinoSoftwareFinal.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
151
152
153
154
155
156
157
158
159
160
161
#include "IRremote.h"
#include <avr/pgmspace.h>
int receiver = 8;
IRrecv irrecv(receiver);
decode_results results;
int ir=0;
int row[] = {4,5,6,7};
int dial = A3;
int latchPin = 10;
int clockPin = 12;
int dataPin = 9;
int play = 0;
const int totalsize = 6;
prog_uint16_t* frames[totalsize];
//We are going to use Program memory instead of regular memory because the arduino has a limit
//on primitive data types. My setup involves an analog rotary potentiometer attached to pin A3
//in order to control the time between each frame of each animation, and an IR remote attached to control the cube,
//to pin 8. The bottom row of the LED cube is connected to pin 4, and
//2nd to 5, 3rd to 6, and top to 7. The columns of the cube are connected to 2 daisy chained
//74HC595 shift registers. Each animation is stored in an array of program memory unsigned ints
//starting with frame0. You use the output generated from the Processing.org application in order
//to generate these frames. The frames are changed by the infrared remote.
PROGMEM prog_uint16_t frame0[] = {1,0,0,0,1,3,0,0,0,1,7,0,0,0,1,15,0,0,0,1,143,0,0,0,1,2191,0,0,0,1,34959,0,0,0,1,51343,0,0,0,1,59535,0,0,0,1,63631,0,0,0,1,63887,0,0,0,1,63903,0,0,0,1,63935,0,0,0,1,63999,0,0,0,1,65023,0,0,0,1,65535,0,0,0,1,65535,512,0,0,1,65535,1536,0,0,1,65535,1600,0,0,1,65535,1632,0,0,1,65535,1648,0,0,1,65535,1904,0,0,1,65535,6000,0,0,1,65535,14192,0,0,1,65535,30576,0,0,1,65535,63344,0,0,1,65535,65392,0,0,1,65535,65520,0,0,1,65535,65528,0,0,1,65535,65532,0,0,1,65535,65534,0,0,1,65535,65535,0,0,1,65535,65535,1,0,1,65535,65535,3,0,1,65535,65535,7,0,1,65535,65535,15,0,1,65535,65535,143,0,1,65535,65535,2191,0,1,65535,65535,34959,0,1,65535,65535,51343,0,1,65535,65535,59535,0,1,65535,65535,63631,0,1,65535,65535,63887,0,1,65535,65535,63903,0,1,65535,65535,63935,0,1,65535,65535,63999,0,1,65535,65535,65023,0,1,65535,65535,65535,0,1,65535,65535,65535,512,1,65535,65535,65535,1536,1,65535,65535,65535,1600,1,65535,65535,65535,1632,1,65535,65535,65535,1648,1,65535,65535,65535,1904,1,65535,65535,65535,6000,1,65535,65535,65535,14192,1,65535,65535,65535,30576,1,65535,65535,65535,63344,1,65535,65535,65535,65392,1,65535,65535,65535,65520,1,65535,65535,65535,65528,1,65535,65535,65535,65532,1,65535,65535,65535,65534,1,65535,65535,65535,65535,1,65535,65535,65535,65534,1,65535,65535,65535,65532,1,65535,65535,65535,65528,1,65535,65535,65535,65520,1,65535,65535,65535,65392,1,65535,65535,65535,63344,1,65535,65535,65535,30576,1,65535,65535,65535,14192,1,65535,65535,65535,6000,1,65535,65535,65535,1904,1,65535,65535,65535,1648,1,65535,65535,65535,1632,1,65535,65535,65535,1600,1,65535,65535,65535,1536,1,65535,65535,65535,512,1,65535,65535,65535,0,1,65535,65535,65023,0,1,65535,65535,63999,0,1,65535,65535,63935,0,1,65535,65535,63903,0,1,65535,65535,63887,0,1,65535,65535,63631,0,1,65535,65535,59535,0,1,65535,65535,51343,0,1,65535,65535,34959,0,1,65535,65535,2191,0,1,65535,65535,143,0,1,65535,65535,15,0,1,65535,65535,7,0,1,65535,65535,3,0,1,65535,65535,1,0,1,65535,65535,0,0,1,65535,65534,0,0,1,65535,65532,0,0,1,65535,65528,0,0,1,65535,65520,0,0,1,65535,65392,0,0,1,65535,63344,0,0,1,65535,30576,0,0,1,65535,14192,0,0,1,65535,6000,0,0,1,65535,1904,0,0,1,65535,1648,0,0,1,65535,1632,0,0,1,65535,1600,0,0,1,65535,1536,0,0,1,65535,512,0,0,1,65535,0,0,0,1,65023,0,0,0,1,63999,0,0,0,1,63935,0,0,0,1,63903,0,0,0,1,63887,0,0,0,1,63631,0,0,0,1,59535,0,0,0,1,51343,0,0,0,1,34959,0,0,0,1,2191,0,0,0,1,143,0,0,0,1,15,0,0,0,1,7,0,0,0,1,3,0,0,0,1,1,0,0,0,1,0,0,0,0,1,0,0,0,0,1};
PROGMEM prog_uint16_t frame1[] = {0,1024,0,0,1,0,1024,32,0,1,0,1056,32,0,1,0,1056,1056,0,1,0,1568,1056,0,1,0,1568,1120,0,1,0,1632,1120,0,1,0,1632,1632,0,1,8192,1632,1632,2,1,8196,1632,1648,2050,1,8212,1632,1648,2306,1,8212,20064,1648,2306,1,8212,20072,1648,2818,1,8404,24168,9840,2818,1,8404,24170,9840,27394,1,8407,24170,10096,27394,1,8407,24170,10232,31490,1,12759,24170,10232,31490,1,61911,24170,14328,31490,1,61911,24170,63480,64258,1,61911,24170,63480,64458,1,63447,24170,65528,64458,1,63447,56955,65528,64458,1,65527,56955,65528,64458,1,65527,57211,65528,64458,1,65535,57211,65528,64507,1,65535,57211,65531,64507,1,65535,57343,65531,64507,1,65535,65535,65535,65535,1,65535,65535,65535,65535,51,65534,65535,32767,65535,1,57342,57343,32763,65535,1,57342,57279,32507,63483,1,55290,57279,31483,63451,1,54250,40895,31449,63451,1,54250,40879,31449,55003,1,54242,40875,23256,22235,1,54242,40873,23248,22234,1,17378,4001,23248,18130,1,17120,4001,23248,18130,1,17120,4000,21200,17042,1,544,3232,21200,16896,1,544,3232,576,512,1,0,1152,576,0,1,0,0,0,0,51};
PROGMEM prog_uint16_t frame2[] = {65535,0,0,0,1,0,65535,0,0,1,0,0,65535,0,1,0,0,0,65535,1,0,0,0,65535,1,0,0,65535,65535,1,0,65535,65535,65535,1,65535,65535,65535,65535,4,65535,65535,65535,0,1,65535,65535,0,0,1,65535,0,0,0,1,0,0,0,0,2,36873,0,0,0,1,36873,36873,0,0,1,36873,36873,36873,0,1,36873,36873,36873,36873,1,47133,47133,47133,47133,1,63903,63903,63903,63903,1,65535,63903,63903,63903,1,65535,65535,63903,63903,1,65535,65535,65535,63903,1,65535,65535,65535,65535,2,65520,65520,65520,65520,1,65280,65280,65280,65280,1,61440,61440,61440,61440,4,5760,5760,5760,5760,1,4680,4680,4680,4680,1,4644,4644,4644,4644,1,4369,4369,4369,4369,4,16929,16929,16929,16929,1,33825,33825,33825,33825,1,2145,2145,2145,2145,1,15,15,15,15,4,15,240,240,3840,1,15,240,3840,61440,1,15,4080,61440,0,1,65535,0,0,0,6,65535,65535,0,0,1,65535,0,65535,0,1,65535,0,0,65535,1,65535,0,0,0,1,65535,65535,0,0,1,65535,0,65535,0,1,65535,0,0,65535,2,65535,65535,0,65535,1,65535,65535,65535,65535,10,65535,65535,65535,0,1,65535,65535,0,0,1,65535,0,0,0,1,0,0,0,0,2,34952,34952,34952,34952,1,52428,52428,52428,52428,1,61166,61166,61166,61166,1,65535,65535,65535,65535,1,30583,30583,30583,30583,1,13107,13107,13107,13107,1,4369,4369,4369,4369,1,0,0,0,0,1,0,0,0,0,1,65535,0,0,0,1,65535,65535,0,0,1,65535,65535,65535,0,1,65535,65535,65535,65535,1,0,65535,65535,65535,1,0,0,65535,65535,1,0,0,0,65535,1,0,0,0,0,1,0,0,0,0,1,4369,4369,4369,4369,1,13107,13107,13107,13107,1,30583,30583,30583,30583,1,65535,65535,65535,65535,1,61166,61166,61166,61166,1,52428,52428,52428,52428,1,34952,34952,34952,34952,1,34952,34952,34952,34952,1,51336,51336,51336,51336,1,59528,59528,59528,59528,1,63624,63624,63624,63624,1,63880,63880,63880,63880,1,63896,63896,63896,63896,1,63897,63897,63897,63897,1,63899,63899,63899,63899,1,63903,63903,63903,63903,1,63903,63903,63903,32769,1,63903,63903,32769,32769,1,63903,32769,32769,32769,1,32769,32769,32769,32769,1,16386,16386,16386,16386,1,8196,8196,8196,8196,1,4104,4104,4104,4104,1,384,384,384,384,1,2064,2064,2064,2064,1,32769,32769,32769,32769,1,16386,16386,16386,16386,1,8196,8196,8196,8196,1,4104,4104,4104,4104,1,384,384,384,384,1,2064,2064,2064,2064,1,32769,32769,32769,32769,4,2064,2064,2064,2064,1,384,384,384,384,1,4104,4104,4104,4104,1,8196,8196,8196,8196,1,16386,16386,16386,16386,1,32769,32769,32769,32769,1,2064,2064,2064,2064,1,384,384,384,384,1,4104,4104,4104,4104,1,8196,8196,8196,8196,1,16386,16386,16386,16386,1,32769,32769,32769,32769,4,0,32769,32769,32769,1,0,0,32769,32769,1,0,0,0,32769,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1};
PROGMEM prog_uint16_t frame3[] = {1,0,0,0,1,3,0,0,0,1,7,0,0,0,1,15,0,0,0,1,15,8,0,0,1,15,12,0,0,1,15,14,0,0,1,15,15,0,0,1,15,15,1,0,1,15,15,3,0,1,15,15,7,0,1,15,15,15,0,1,15,15,15,8,1,15,15,15,12,1,15,15,15,14,1,15,15,15,15,1,15,15,15,31,1,15,15,15,63,1,15,15,15,127,1,15,15,15,255,1,15,15,143,255,1,15,15,207,255,1,15,15,239,255,1,15,15,255,255,1,15,31,255,255,1,15,63,255,255,1,15,127,255,255,1,15,255,255,255,1,143,255,255,255,1,207,255,255,255,1,239,255,255,255,1,255,255,255,255,1,511,255,255,255,1,1023,255,255,255,1,2047,255,255,255,1,4095,255,255,255,1,4095,2303,255,255,1,4095,3327,255,255,1,4095,3839,255,255,1,4095,4095,255,255,1,4095,4095,511,255,1,4095,4095,1023,255,1,4095,4095,2047,255,1,4095,4095,4095,255,1,4095,4095,4095,2303,1,4095,4095,4095,3327,1,4095,4095,4095,3839,1,4095,4095,4095,4095,1,4095,4095,4095,8191,1,4095,4095,4095,16383,1,4095,4095,4095,32767,1,4095,4095,4095,65535,1,4095,4095,36863,65535,1,4095,4095,53247,65535,1,4095,4095,61439,65535,1,4095,4095,65535,65535,1,4095,8191,65535,65535,1,4095,16383,65535,65535,1,4095,32767,65535,65535,1,4095,65535,65535,65535,1,36863,65535,65535,65535,1,53247,65535,65535,65535,1,61439,65535,65535,65535,1,65535,65535,65535,65535,1,61439,65535,65535,65535,1,53247,65535,65535,65535,1,36863,65535,65535,65535,1,4095,65535,65535,65535,1,4095,32767,65535,65535,1,4095,16383,65535,65535,1,4095,8191,65535,65535,1,4095,4095,65535,65535,1,4095,4095,61439,65535,1,4095,4095,53247,65535,1,4095,4095,36863,65535,1,4095,4095,4095,65535,1,4095,4095,4095,32767,1,4095,4095,4095,16383,1,4095,4095,4095,8191,1,4095,4095,4095,4095,1,4095,4095,4095,3839,1,4095,4095,4095,3327,1,4095,4095,4095,2303,1,4095,4095,4095,255,1,4095,4095,2047,255,1,4095,4095,1023,255,1,4095,4095,511,255,1,4095,4095,255,255,1,4095,3839,255,255,1,4095,3327,255,255,1,4095,2303,255,255,1,4095,255,255,255,1,2047,255,255,255,1,1023,255,255,255,1,511,255,255,255,1,255,255,255,255,1,239,255,255,255,1,207,255,255,255,1,143,255,255,255,1,15,255,255,255,1,15,127,255,255,1,15,63,255,255,1,15,31,255,255,1,15,15,255,255,1,15,15,239,255,1,15,15,207,255,1,15,15,143,255,1,15,15,15,255,1,15,15,15,127,1,15,15,15,63,1,15,15,15,31,1,15,15,15,15,1,15,15,15,14,1,15,15,15,12,1,15,15,15,8,1,15,15,15,0,1,15,15,7,0,1,15,15,3,0,1,15,15,1,0,1,15,15,0,0,1,15,14,0,0,1,15,12,0,0,1,15,8,0,0,1,15,0,0,0,1,7,0,0,0,1,3,0,0,0,1,1,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1};
PROGMEM prog_uint16_t frame4[] = {1,0,0,0,1,3,0,0,0,1,7,0,0,0,1,15,0,0,0,1,143,0,0,0,1,2191,0,0,0,1,34959,0,0,0,1,34959,32768,0,0,1,34959,32768,32768,0,1,34959,32768,32768,32768,1,34959,32768,32768,34816,1,34959,32768,32768,34944,1,34959,32768,32768,34952,1,34959,32768,32776,34952,1,34959,32776,32776,34952,1,34975,32776,32776,34952,1,35231,32776,32776,34952,1,39327,32776,32776,34952,1,47519,32776,32776,34952,1,63903,32776,32776,34952,1,63903,32776,32776,51336,1,63903,32776,32776,59528,1,63903,32776,32776,63624,1,63903,32776,32776,63880,1,63903,32776,32776,63896,1,63903,32776,32776,63897,1,63903,32776,32777,63897,1,63903,32777,32777,63897,1,63903,36873,32777,63897,1,63903,36873,36873,63897,1,63903,36873,36873,63899,1,63903,36873,36873,63903,1,63903,36905,36873,63903,1,63903,36937,36873,63903,1,63903,37001,36873,63903,1,63903,36873,37001,63903,1,63903,36873,37897,63903,1,63903,36873,37385,63903,1,63903,36873,45065,63903,1,63903,36873,37385,63903,1,63903,37385,36873,63903,1,63903,36905,36873,63903,1,63903,36875,36873,63903,1,63935,36873,36873,63903,1,63903,36905,36873,63903,1,63903,37897,36873,63903,1,63903,36873,37897,63903,1,63903,36873,36873,64415,1,63903,36873,36905,63903,1,63903,36873,36937,63903,1,63903,37001,36873,63903,1,63903,36873,36937,63903,1,63903,36873,37897,63903,1,63903,36873,36873,64927,1,63903,36873,37897,63903,1,63903,36873,36905,63903,1,63903,36905,36873,63903,1,64927,36873,36873,63903,1,63935,36873,36873,63903,1,63903,36905,36873,63903,1,63903,36875,36873,63903,1,63903,36937,36873,63903,1,63903,36873,37897,63903,1,63903,36873,45065,63903,1,63903,36873,36873,64415,1,63903,36873,36905,63903,1,63903,36937,36873,63903,1,63903,36875,36873,63903,1,63935,36873,36873,63903,1,63903,37385,36873,63903,1,63903,37897,36873,63903,1,63903,36873,37001,63903,1,63903,36873,36877,63903,1,63903,36873,36905,63903,1,63903,37385,36873,63903,1,63903,37897,36873,63903,1,63903,36873,38921,63903,1,63903,36873,36937,63903,1,63903,36873,36905,63903,1,63903,36875,36873,63903,1,63935,36873,36873,63903,1,63903,36889,36873,63903,1,63903,36873,37129,63903,1,63903,36873,37385,63903,1,63903,36873,36873,64415,1,63903,36873,36937,63903,1,63903,36937,36873,63903,1,63935,36873,36873,63903,1,63903,36889,36873,63903,1,63903,36875,36873,63903,1,63903,36937,36873,63903,1,63903,37897,36873,63903,1,63903,45065,36873,63903,1,63903,36873,37897,63903,1,63903,36873,36905,63903,1,63903,36873,36875,63903,1,63903,36873,36873,63935,1,63903,36873,36873,63967,1,63903,36873,36937,63903,1,63903,36937,36873,63903,1,64415,36873,36873,63903,1,63903,45065,36873,63903,1,63903,37897,36873,63903,1,63903,36873,36905,63903,1,63903,36873,37129,63903,1,63903,36873,36873,64415,1,63903,36873,36873,63967,1,63903,36873,37001,63903,1,63903,36873,36877,63903,1,63903,36875,36873,63903,1,63935,36873,36873,63903,1,63903,37385,36873,63903,1,63903,36873,37897,63903,1,63903,36873,36937,63903,1,63903,36873,36875,63903,1,63903,36905,36873,63903,1,63903,37897,36873,63903,1,63903,38921,36873,63903,1,63967,36873,36873,63903,1,63903,37385,36873,63903,1,63903,36873,37897,63903,1,63903,36873,36873,63967,1,63903,36873,36877,63903,1,63903,36937,36873,63903,1,63967,36873,36873,63903,1,64927,36873,36873,63903,1,63903,37385,36873,63903,1,63903,36873,36905,63903,1,63903,36873,36937,63903,1,63903,36873,36873,64927,1,63903,36873,37385,63903,1,63903,37385,36873,63903,1,63903,37129,36873,63903,1,63935,36873,36873,63903,1,63967,36873,36873,63903,1,63903,36873,36873,63899,1,63903,36873,36873,63897,1,63903,36873,32777,63897,1,63903,32777,32777,63897,1,63903,32776,32777,63897,1,63903,32776,32776,63897,1,63903,32776,32776,63896,1,63903,32776,32776,63880,1,63903,32776,32776,63624,1,63903,32776,32776,59528,1,63903,32776,32776,51336,1,63903,32776,32776,34952,1,47519,32776,32776,34952,1,39327,32776,32776,34952,1,35231,32776,32776,34952,1,34975,32776,32776,34952,1,34959,32776,32776,34952,1,34959,32768,32776,34952,1,34959,32768,32768,34944,1,34959,32768,32768,34816,1,34959,32768,32768,32768,1,34959,32768,32768,0,1,34959,0,0,0,1,2191,0,0,0,1,143,0,0,0,1,15,0,0,0,1,7,0,0,0,1,3,0,0,0,1,1,0,0,0,1,0,0,0,0,1,0,0,0,0,1};
PROGMEM prog_uint16_t frame5[] = {255,255,255,255,1,254,255,255,33023,1,252,255,255,49407,1,248,255,255,57599,1,240,255,255,61695,1,240,247,4351,61695,1,240,243,12543,61695,1,240,241,28927,61695,1,240,240,61695,61695,1,240,33008,61694,61695,1,240,49392,61692,61695,1,240,57584,61688,61695,1,240,61680,61680,61695,1,4336,61680,61680,61687,1,12528,61680,61680,61683,1,28912,61680,61680,61681,1,61680,61680,61680,61680,1,63728,61680,61680,61664,1,64752,61680,61680,61632,1,65264,61680,61680,61568,1,65520,61680,61680,61440,1,65520,61936,61552,61440,1,65520,62448,61488,61440,1,65520,63472,61456,61440,1,65520,65520,61440,61440,1,65520,65504,63488,61440,1,65520,65472,64512,61440,1,65520,65408,65024,61440,1,65520,65280,65280,61440,1,65392,65280,65280,61696,1,65328,65280,65280,62208,1,65296,65280,65280,63232,1,65280,65280,65280,65280,1,65024,65280,65280,65288,1,64512,65280,65280,65292,1,63488,65280,65280,65294,1,61440,65280,65280,65295,1,61440,63232,65281,65295,1,61440,62208,65283,65295,1,61440,61696,65287,65295,1,61440,61440,65295,65295,1,61440,61448,65039,65295,1,61440,61452,64527,65295,1,61440,61454,63503,65295,1,61440,61455,61455,65295,1,61441,61455,61455,63247,1,61443,61455,61455,62223,1,61447,61455,61455,61711,1,61455,61455,61455,61455,1,61583,61455,61455,57359,1,61647,61455,61455,49167,1,61679,61455,61455,32783,1,61695,61455,61455,15,1,61695,61471,28687,15,1,61695,61503,12303,15,1,61695,61567,4111,15,1,61695,61695,15,15,1,61695,57599,143,15,1,61695,49407,207,15,1,61695,33023,239,15,1,61695,255,255,15,1,28927,255,255,31,1,12543,255,255,63,1,4351,255,255,127,1,255,255,255,255,1};
PROGMEM prog_uint16_t frameoff[] = {0,0,0,0,0};
//Update this value with how many arrays of animations you have!
int sizes[6];
void setup(){
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
irrecv.enableIRIn();
Serial.begin(9600);
frames[0] = frame0;
frames[1] = frame1;
frames[2] = frame2;
frames[3] = frame3;
frames[4] = frame4;
frames[5] = frame5;
frames[totalsize] = frameoff;
sizes[0] = sizeof(frame0)/2;
sizes[1] = sizeof(frame1)/2;
sizes[2] = sizeof(frame2)/2;
sizes[3] = sizeof(frame3)/2;
sizes[4] = sizeof(frame4)/2;
sizes[5] = sizeof(frame5)/2;
sizes[totalsize] = sizeof(frameoff)/2;
}
//1 and 300 and 5
int time = 100;
int mtime = 300;
int counter = 1;
int dialval;
void loop(){
//dialval = analogRead(dial);
//dialval = map(dialval,0,1023,0,10);
int playis=play;
int w=0;
for(int i=0; i< sizes[play];i = i+5){
int temp = counter * pgm_read_word_near(frames[play]+(i+4))+dialval;
for(int q = 0;q<temp;q++){
if(play != playis)
break;
Serial.println(temp);
conv(pgm_read_word_near(frames[play]+i),(i-w) % 4);
conv(pgm_read_word_near(frames[play]+(i+1)),((i+1)-w) % 4);
conv(pgm_read_word_near(frames[play]+(i+2)),((i+2)-w) % 4);
conv(pgm_read_word_near(frames[play]+(i+3)),((i+3)-w) % 4);
check();
}
w++;
}
}
void conv(unsigned int num, int k){
byte first,second,third,fourth;
first = highByte(num);
first = first >> 4;
first = first << 4;
second = highByte(num);
second = second << 4;
second = second >> 4;
third = lowByte(num);
third = third >> 4;
third = third << 4;
fourth = lowByte(num);
fourth = fourth << 4;
fourth = fourth >> 4;
led(fourth,k,1);
led(third,k,1);
led(second,k,0);
led(first,k,0);
}
void led(byte leds,int k,int r){
pinMode(row[k],OUTPUT);
digitalWrite(row[k],LOW);
if(r==0){
digitalWrite(latchPin, 0);
shiftOut(dataPin, clockPin,MSBFIRST, leds);
shiftOut(dataPin, clockPin,MSBFIRST, 0);
digitalWrite(latchPin, 1);
}
else{
digitalWrite(latchPin, 0);
shiftOut(dataPin, clockPin,MSBFIRST, 0);
shiftOut(dataPin, clockPin,MSBFIRST,leds);
digitalWrite(latchPin, 1);
}
unsigned long microtime = micros();
while (microtime+mtime > micros()){
check();
}
pinMode(row[k],INPUT);
digitalWrite(latchPin, 0);
shiftOut(dataPin, clockPin,MSBFIRST, 0);
shiftOut(dataPin, clockPin,MSBFIRST, 0);
digitalWrite(latchPin, 1);
}
void check(){
//Check if a command is received from the infrared receiver
//Serial.println(analogRead(dial));
//analogRead(dial);
dialval = analogRead(dial);
dialval = map(dialval,0,1023,1,20);
if (irrecv.decode(&results)) // have we received an IR signal?
{
int IRvalue=results.value;
ir=results.value;
delay(2);
Serial.println(IRvalue); // display it on serial monitor in hexadecimal
irrecv.resume();
}
if(ir== 25245) //play pause
play = (play + 1) % totalsize;
if(ir== -23971){
if(play== totalsize)
play = 0;
else
play = totalsize;
}
ir=0;
}