-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathled_cube.c
More file actions
executable file
·139 lines (128 loc) · 2.46 KB
/
led_cube.c
File metadata and controls
executable file
·139 lines (128 loc) · 2.46 KB
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
#include <avr/io.h>
#include <view.h>
#include <controller.h>
//Define functions
//======================
void ioinit(void); //Initializes IO
void delay_ms(uint16_t x); //General purpose delay
void testLEDs(void);
void testMultiplexing(void);
void testPowerConsumption(void);
//======================
char model[3][3][3] = {
{
{0, 0, 1},
{0, 0, 1},
{1, 1, 1}
},
{
{0, 0, 1},
{0, 0, 1},
{1, 1, 1}
},
{
{1, 1, 1},
{1, 1, 1},
{1, 1, 1}
}
};
int main (void)
{
ioinit(); //Setup IO pins and defaults
while(1){
// for (int i = 0; i < 10; ++i)
// {
// for (int z = 0; z < 3; ++z)
// {
// clearAllVoxels();
// for (int y = 0; y < 3; ++y)
// {
// for (int x = 0; x < 3; ++x)
// {
// setVoxel(z, y, x, 1);
// }
// }
// delay_ms(300);
// }
// }
// clearAllVoxels();
// loadModel(model);
// delay_ms(2000);
// sphericalWave();
roam();
delay_ms(200);
}
return(0);
}
void ioinit (void)
{
init_view();
init_controller();
}
void roam(void){
static int x = 0;
static int y = 0;
static int z = 0;
if (down_pressed() && y < MAX_Y - 1)
{
y = y + 1;
}
else if (up_pressed() && y > 0)
{
y = y - 1;
}
else if (right_pressed() && x < MAX_X - 1)
{
x = x + 1;
}
else if (left_pressed() && x > 0)
{
x = x - 1;
}
else if (rise_pressed() && z < MAX_Z - 1)
{
z = z + 1;
}
else if (fall_pressed() && z > 0)
{
z = z - 1;
}
clearAllVoxels();
setVoxel(z, y, x, 1);
}
void sphericalWave(void){
for (int i = 0; i < 3; ++i)
{
clearAllVoxels();
switch(i){
case 0:
setVoxel(0,0,0,1);
break;
case 1:
setVoxel(0,0,1,1);
setVoxel(0,1,0,1);
setVoxel(0,1,1,1);
setVoxel(1,0,0,1);
setVoxel(1,0,1,1);
setVoxel(1,1,0,1);
setVoxel(1,1,1,1);
break;
case 2:
loadModel(model);
break;
}
delay_ms(300);
}
}
//General short delays
void delay_ms(uint16_t x)
{
uint8_t y, z;
for ( ; x > 0 ; x--){
for ( y = 0 ; y < 90 ; y++){
for ( z = 0 ; z < 6 ; z++){
asm volatile ("nop");
}
}
}
}