aboutsummaryrefslogtreecommitdiff
path: root/Arduino/Libraies/AS1107/examples/LEDMatrix/LEDMatrix.pde
blob: 377331d5d00d76fc69d16f0c540a00c710e182e1 (plain)
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
// test program for three cascaded AS1107
// if you got a different configuration you need to
// modify the library itself.

#include <AS1107.h>

// Arduino pins
const byte CsnPin = 2 ; // Chip select (Low active)
const byte ClkPin = 3 ; // Serial Clock
const byte DataPin = 4 ; // Serial Data

byte buffer [ 24 ] ; // Screen buffer (No. of modules * 8)
AS1107 matrix ( CsnPin, ClkPin, DataPin ) ;

const byte d = 0 ;
int count= 1 ;
void setup ( )
{
matrix. Init ( buffer ) ;
matrix. SetScrollText ( " Three 8x8 LED dot matrix modules driven by three AS1107 LED controllers using just four I/O pins of the Arduino for serial data. That is surprisingly fast, look:" , 1 ) ;
}

void loop ( )
{
if ( matrix. TextScroll ( ) ) {
delay ( 2000 ) ;
for ( int i= 0 ; i<= 7 ; i++ ) {
matrix. ShiftUp ( ) ;
delay ( 50 ) ;
matrix. Update ( ) ;
}
for ( int i= 0 ; i<= 10 ; i++ ) {
CirclePulsate ( ) ;
}
StarsDown ( ) ;
for ( int i= 0 ; i<= 5 ; i++ ) {
Rotator1 ( ) ;
}
StarsRight ( ) ;
for ( int i= 0 ; i<=AS1107:: Maxx ; i++ ) {
matrix. ShiftRight ( ) ;
delay ( 5 ) ;
matrix. Update ( ) ;
}
for ( int i= 1 ; i<= 3 ; i++ )
{
bounce ( ) ;
}
}
delay ( 10 ) ;
}

void CirclePulsate ( )
{
for ( int i= 0 ; i<= 15 ; i++ ) {
matrix. Clear ( ) ;
matrix. DrawEllipse ( AS1107:: Maxx / 2 , 4 ,i,i ) ;
matrix. Update ( ) ;
delay ( d ) ;
}
}
void StarsDown ( )
{
for ( int i= 0 ; i<= 200 ; i++ ) {
matrix. ShiftDown ( ) ;
matrix. SetLed ( ( byte ) random ( 0 ,AS1107:: Maxx + 1 ) , 0 , 1 ) ;
matrix. Update ( ) ;
delay ( d ) ;
}
}
void StarsRight ( )
{
for ( int i= 0 ; i<= 200 ; i++ ) {
matrix. ShiftRight ( ) ;
matrix. SetLed ( 0 , ( byte ) random ( 0 ,AS1107:: Maxy + 1 ) , 1 ) ;
matrix. Update ( ) ;
delay ( d ) ;
}
}
void Rotator1 ( )
{
for ( int i= 0 ; i<=AS1107:: Maxx - 1 ; i++ ) {
matrix. Clear ( ) ;
matrix. DrawLine ( i, 0 ,AS1107:: Maxx -i,AS1107:: Maxy ) ;
matrix. Update ( ) ;
delay ( d ) ;
}
for ( int i= 0 ; i<= 6 ; i++ ) {
matrix. Clear ( ) ;
matrix. DrawLine ( AS1107:: Maxx ,i, 0 , 7 -i ) ;
matrix. Update ( ) ;
delay ( d ) ;
}
}

void bounce ( )
{
int rad= 0 ;
float y=random ( 0 ,AS1107:: Maxy + 1 ) ;
float x=random ( 0 ,AS1107:: Maxx + 1 ) ;
float xacc=random ( 0 , 5 ) - 2 ;
float yacc=random ( 0 , 5 ) - 2 ;
float yg= 0 . 08 ;
if ( xacc == 0 ) xacc == 1 ;
if ( yacc == 0 ) yacc == - 1 ;
for ( int i= 1 ; i<= 300 ; i++ )
{
x+=xacc;
y+=yacc;
yacc += yg;
if ( x >= ( AS1107:: Maxx -rad ) ) {
xacc = -xacc* 0 . 9 ;
x= AS1107:: Maxx -rad;
}
else if ( x <= rad ) {
xacc = -xacc* 0 . 8 ;
x= rad;
}
if ( y >= ( AS1107:: Maxy -rad ) ) {
yacc = - ( yacc* 0 . 80 ) ;
y= AS1107:: Maxy -rad;
}
else if ( y <= rad ) {
yacc = -yacc* 0 . 8 ;
y= rad;
}
matrix. Clear ( ) ;
matrix. SetLed ( x,y, 1 ) ;
matrix. Update ( ) ;
}
}