-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathledcube.h
102 lines (74 loc) · 1.7 KB
/
ledcube.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
#ifndef ledcube_h
#define ledcube_h
#include "MsTimer2.h"
#include "fastShiftOut.h"
#include "cube.h"
#define STR_PIN 10
#define STAGE_ACTIVE LOW
#define STAGE_DISACTIVE HIGH
namespace LEDCUBE {
void begin();
void clear(); //matrixをすべてLOW
void pull(Cube mat);
void update(Cube mat);
void update(int x,int y,int z,boolean value);
void set(int x,int y,int z);
void clr(int x,int y,int z);
void drawingStage();
boolean get(int x,int y,int z);
boolean buffer[72];
Cube cube;
fastShiftOut ledcube;
};
void LEDCUBE::begin(){
ledcube.begin(STR_PIN);
ledcube.dataLink(buffer,72); //(8+1)*8bit
clear();
for(byte i=0; i<8; i++) {
drawingStage();
delay(1);
}
MsTimer2::set(1,drawingStage);
MsTimer2::start();
}
void LEDCUBE::drawingStage(){
static byte stage = 0;
//発光させる段の選択(一段だけアクティブに)[64~71]
for(byte i=64; i<72; i++) buffer[i] = STAGE_DISACTIVE;
buffer[64+stage] = STAGE_ACTIVE;
//選択した段の発光箇所データ反映[0~63]
for(byte i=0; i<8; i++){
for(byte j=0; j<8; j++){
buffer[(i*8) + j] = cube.get(i,j,stage);
}
}
//データ送信
ledcube.send();
//次回の発光段の指定
stage = (++stage) % 8;
}
//matrixをすべてLOW
void LEDCUBE::clear(){
cube.clearAll();
update(cube);
}
void LEDCUBE::pull(Cube mat){
mat = cube;
}
void LEDCUBE::update(Cube mat){
cube = mat;
}
void LEDCUBE::update(int x,int y,int z,boolean value){
cube.set(x,y,z,value);
}
void LEDCUBE::set(int x,int y,int z){
cube.set(x,y,z);
}
void LEDCUBE::clr(int x,int y,int z){
cube.clr(x,y,z);
}
boolean LEDCUBE::get(int x,int y,int z){
return cube.get(x,y,z);
}
#undef STR_PIN
#endif