Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
int pin_A = 5;
int pin_B = 6;
int pin_C = 7;
int pin_D = 8;
int pin_E = 9;
int pin_F = 10;
int pin_G = 11;
int pin_H = 12;
int pin_I = 13;
int pin_1 = 2;
int pin_2 = 3;
int pin_3 = 4;
int anodes[] = {
pin_A,
pin_B,
pin_C,
pin_D,
pin_E,
pin_F,
pin_G,
pin_H,
pin_I,
};
int cathodes[] = {
pin_1,
pin_2,
pin_3
};
const int frames = 8;
boolean test_animation[frames][3][9] = {
/*
{ //1
{ 0, 1, 0,
0, 0, 0,
0, 0, 0 },
{ 0, 0, 0,
0, 1, 0,
0, 0, 0 },
{ 0, 0, 0,
0, 0, 0,
0, 0, 0 }
}, { //2
{ 0, 0, 0,
0, 1, 0,
0, 0, 0 },
{ 0, 1, 0,
1, 0, 1,
0, 1, 0 },
{ 0, 0, 0,
0, 1, 0,
0, 0, 0 }
}, { //3
{ 1, 1, 1,
1, 0, 1,
1, 1, 1 },
{ 1, 0, 1,
0, 0, 0,
1, 0, 1 },
{ 1, 1, 1,
1, 0, 1,
1, 1, 1 },
}, { //4
{ 0, 0, 0,
0, 0, 0,
0, 0, 0 },
{ 0, 0, 0,
0, 0, 0,
0, 0, 0 },
{ 0, 0, 0,
0, 0, 0,
0, 0, 0 }
},
*/
{ //5
{
0, 0, 0,
0, 1, 0,
0, 0, 0 }
,
{
0, 1, 0,
0, 1, 0,
0, 0, 0 }
,
{
0, 0, 0,
0, 1, 0,
0, 0, 0 }
}
, { //6
{
0, 0, 0,
0, 1, 0,
0, 0, 0 }
,
{
1, 0, 0,
0, 1, 0,
0, 0, 0 }
,
{
0, 0, 0,
0, 1, 0,
0, 0, 0 }
}
, { //7
{
0, 0, 0,
0, 1, 0,
0, 0, 0 }
,
{
0, 0, 0,
1, 1, 0,
0, 0, 0 }
,
{
0, 0, 0,
0, 1, 0,
0, 0, 0 }
}
, { //8
{
0, 0, 0,
0, 1, 0,
0, 0, 0 }
,
{
0, 0, 0,
0, 1, 0,
1, 0, 0 }
,
{
0, 0, 0,
0, 1, 0,
0, 0, 0 }
}
, { //9
{
0, 0, 0,
0, 1, 0,
0, 0, 0 }
,
{
0, 0, 0,
0, 1, 0,
0, 1, 0 }
,
{
0, 0, 0,
0, 1, 0,
0, 0, 0 }
}
, { //10
{
0, 0, 0,
0, 1, 0,
0, 0, 0 }
,
{
0, 0, 0,
0, 1, 0,
0, 0, 1 }
,
{
0, 0, 0,
0, 1, 0,
0, 0, 0 }
}
, { //11
{
0, 0, 0,
0, 1, 0,
0, 0, 0 }
,
{
0, 0, 0,
0, 1, 1,
0, 0, 0 }
,
{
0, 0, 0,
0, 1, 0,
0, 0, 0 }
}
, { //12
{
0, 0, 0,
0, 1, 0,
0, 0, 0 }
,
{
0, 0, 1,
0, 1, 0,
0, 0, 0 }
,
{
0, 0, 0,
0, 1, 0,
0, 0, 0 }
}
};
void setup() {
Serial.begin(9600);
for (int i=0; i<3; i++) {
pinMode(cathodes[i], OUTPUT);
}
for (int i=0; i<9; i++) {
pinMode(anodes[i], OUTPUT);
}
all_off();
}
void loop() {
animation (test_animation, 22, 4); //length, cycles
/**/
//
all_fading();
//
all_after();
//
snow();
//
pyramide();
pyramide();
pyramide();
//
all_after2();
//
snow2();
//
all_off();
/**/
}
void all_fading() {
int factor = 1;
for (int i=0; i<3; i++) {
digitalWrite(cathodes[i], LOW);
for (int t=0;t<16;t++) {
for (int j=0; j<9; j++) {
digitalWrite(anodes[j], HIGH);
}
delay(t*factor);
for (int j=0; j<9; j++) {
digitalWrite(anodes[j], LOW);
}
delay((16-t)*factor);
}
for (int t=0;t<16;t++) {
for (int j=0; j<9; j++) {
digitalWrite(anodes[j], HIGH);
}
delay((16-t)*factor);
for (int j=0; j<9; j++) {
digitalWrite(anodes[j], LOW);
}
delay(t*factor);
}
digitalWrite(cathodes[i], HIGH);
}
}
void all_after() {
for (int i=0; i<3; i++) {
digitalWrite(cathodes[i], LOW);
for (int j=0; j<9; j++) {
digitalWrite(anodes[j], HIGH);
delay(50);
digitalWrite(anodes[j], LOW);
}
digitalWrite(cathodes[i], HIGH);
}
}
void all_after2() {
for (int i=0; i<3; i++) {
digitalWrite(cathodes[i], LOW);
for (int j=0; j<9; j++) {
for (int t=0;t<16; t++) {
digitalWrite(anodes[j], HIGH);
delay(t);
digitalWrite(anodes[j], LOW);
delay(15-t);
}
for (int t=0;t<16;t++) {
digitalWrite(anodes[j], HIGH);
delay(15-t);
digitalWrite(anodes[j], LOW);
delay(t);
}
}
digitalWrite(cathodes[i], HIGH);
}
}
void snow() {
all_off();
for (int j=0; j<9; j++) {
digitalWrite(anodes[j], HIGH);
for (int i=0; i<3; i++) {
digitalWrite(cathodes[2-i], LOW);
delay(100);
digitalWrite(cathodes[2-i], HIGH);
}
digitalWrite(anodes[j], LOW);
}
}
void snow2() {
all_off();
for (int j=0; j<9; j++) {
for (int i=0; i<3; i++) {
digitalWrite(anodes[j], HIGH);
for (int t=0;t<16;t++) {
digitalWrite(cathodes[2-i], LOW);
delay(t);
digitalWrite(cathodes[2-i], HIGH);
delay((15-t));
}
for (int t=0;t<16;t++) {
digitalWrite(cathodes[2-i], LOW);
delay((15-t));
digitalWrite(cathodes[2-i], HIGH);
delay(t);
}
digitalWrite(anodes[j], LOW);
}
}
}
void all_off() {
for (int i=0; i<3; i++) {
for (int j=0; j<9; j++) {
digitalWrite(anodes[j], LOW);
}
digitalWrite(cathodes[i], HIGH);
}
}
void animation (boolean animation_arr[][3][9], int length, int cycles) {
for (int c=0;c<cycles;c++) {
for (int a=0;a<frames;a++) {
for (int l=0;l<length;l++) {
for (int i=0; i<3; i++) {
digitalWrite(cathodes[i], LOW);
for (int j=0; j<9; j++) {
if (animation_arr[a][i][j]) digitalWrite(anodes[j], HIGH);
else digitalWrite(anodes[j], LOW);
} //j
delayMicroseconds(1000);
digitalWrite(cathodes[i], HIGH);
}//i
}//l
}//a
}//c
}
boolean test[3][9] ={
{
1, 1, 1,
1, 1, 1,
1, 1, 1
}
,
{
0, 1, 0,
1, 1, 1,
0, 1, 0
}
,
{
0, 0, 0,
0, 1, 0,
0, 0, 0
}
};
void pyramide() {
for (int t=1;t<255;t++) {
for (int i=0; i<3; i++) {
digitalWrite(cathodes[i], LOW);
for (int j=0; j<9; j++) {
if (test[i][j]) digitalWrite(anodes[j], HIGH);
else digitalWrite(anodes[j], LOW);
}
delayMicroseconds(255-t);
digitalWrite(cathodes[i], HIGH);
for (int j=0; j<9; j++) {
digitalWrite(anodes[j], LOW);
}
delayMicroseconds(t);
}
}
for (int t=1;t<255;t++) {
for (int i=0; i<3; i++) {
digitalWrite(cathodes[i], LOW);
for (int j=0; j<9; j++) {
if (test[i][j]) digitalWrite(anodes[j], HIGH);
else digitalWrite(anodes[j], LOW);
}
delayMicroseconds(t);
digitalWrite(cathodes[i], HIGH);
for (int j=0; j<9; j++) {
digitalWrite(anodes[j], LOW);
}
delayMicroseconds(255-t);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.