헥헥... Fritzing 으로 그리기 빡쎄네... 휴우
74HC595 8bit Ragister 로 No.1 ~ No.16 LED 줄을 컨트롤
4개의 PN2222 TR을 이용해서 1~4 Floor 를 컨트롤
int dataPin = 13;
int latchPin = 12;
int clockPin = 11;
int analogOut = 10; // using PWM
int level[4] = {5,4,3,2}; // 2 : 1st, 3 : 2nd, 4 : 3rd, 5 : 4th floor
int value = 0;
int value2 = 0;
void setup(){
pinMode(dataPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
analogWrite(analogOut, 0);
Serial.begin(9600);
ani_indi();
ani_col_con();
ani_row_con();
ani_hight_con();
squre_con();
bright_con();
cross_con();
}
void loop(){
cross_con();
}
void writeOutput(){
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, value);
shiftOut(dataPin, clockPin, MSBFIRST, value2);
digitalWrite(latchPin, HIGH);
}
void ani_indi(){
int delay_time = 25;
int seq[31] = {128,64,32,16,8,4,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,4,8,16,32,64,128};
int seq2[31] = {0,0,0,0,0,0,0,0,128,64,32,16,8,4,2,1,2,4,8,16,32,64,128,0,0,0,0,0,0,0,0};
for(int i = 3 ; i >=0 ; i--){
digitalWrite(level[i], HIGH);
for (int n = 0; n<31; n++){
value = seq[n];
value2 = seq2[n];
writeOutput();
delay(delay_time);
}
for(int j = 0 ; j <4 ; j++){digitalWrite(level[j] , LOW);}
}
for(int i = 1 ; i <4 ; i++){
digitalWrite(level[i], HIGH);
for (int n = 0; n<31; n++){
value = seq[n];
value2 = seq2[n];
writeOutput();
delay(delay_time);
}
for(int j = 0 ; j <4 ; j++){digitalWrite(level[j] , LOW);}
}
}
void ani_col_con(){
int delay_time = 100;
int col_con[4][2] = {{136, 136}, {68, 68}, {34, 34}, {17, 17}};
for(int i = 3; i >=0; i--){
digitalWrite(level[i], HIGH);
for(int j = 0; j <4; j++){
value = col_con[j][0];
value2 = col_con[j][1];
writeOutput();
delay(delay_time);
}
for(int k = 3; k>=0 ; k--){
value = col_con[k][0];
value2 = col_con[k][1];
writeOutput();
delay(delay_time);
}
for(int i = 0 ; i <4 ; i++){digitalWrite(level[i] , LOW);}
}
for(int i = 1; i <4; i++){
digitalWrite(level[i], HIGH);
for(int j = 0; j <4; j++){
value = col_con[j][0];
value2 = col_con[j][1];
writeOutput();
delay(delay_time);
}
for(int k = 3; k>=0 ; k--){
value = col_con[k][0];
value2 = col_con[k][1];
writeOutput();
delay(delay_time);
}
for(int i = 0 ; i <4 ; i++){digitalWrite(level[i] , LOW);}
}
}
void ani_row_con(){
int delay_time = 100;
int row_con[4][2] = {{240, 0}, {15, 0}, {0, 240}, {0, 15}};
for(int i = 3; i >=0; i--){
digitalWrite(level[i], HIGH);
for(int j = 0; j <4; j++){
value = row_con[j][0];
value2 = row_con[j][1];
writeOutput();
delay(delay_time);
}
for(int k = 3 ; k >=0; k--){
value = row_con[k][0];
value2 = row_con[k][1];
writeOutput();
delay(delay_time);
}
for(int i = 0 ; i <4 ; i++){digitalWrite(level[i] , LOW);}
}
for(int i = 1; i<4; i++){
digitalWrite(level[i], HIGH);
for(int j = 0; j <4; j++){
value = row_con[j][0];
value2 = row_con[j][1];
writeOutput();
delay(delay_time);
}
for(int k = 3 ; k >=0; k--){
value = row_con[k][0];
value2 = row_con[k][1];
writeOutput();
delay(delay_time);
}
for(int i = 0 ; i <4 ; i++){digitalWrite(level[i] , LOW);}
}
}
void ani_hight_con(){
int delay_time = 100;
int ani_hight_con[4][4][2]={
{{128, 0},{64,0}, {32,0}, {16,0}},
{{8,0}, {4,0}, {2,0}, {1,0}},
{{0,128}, {0,64}, {0,32}, {0,16}},
{{0,8}, {0,4}, {0,2}, {0,1}}};
for(int k=0;k<4;k++){
for(int i = 0 ; i<4 ; i++){
digitalWrite(level[i], HIGH);
value = ani_hight_con[k][i][0];
value2= ani_hight_con[k][i][1];
writeOutput();
delay(delay_time);
}
for(int i=2;i>=0;i--){
digitalWrite(level[i], HIGH);
value = ani_hight_con[k][i][0];
value2= ani_hight_con[k][i][1];
writeOutput();
delay(delay_time);
}
}
for(int k=2;k>=0;k--){
for(int i = 0 ; i<4 ; i++){
digitalWrite(level[i], HIGH);
value = ani_hight_con[k][i][0];
value2= ani_hight_con[k][i][1];
writeOutput();
delay(delay_time);
}
for(int i=2;i>=0;i--){
digitalWrite(level[i], HIGH);
value = ani_hight_con[k][i][0];
value2= ani_hight_con[k][i][1];
writeOutput();
delay(delay_time);
}
}
for(int i = 0 ; i <4 ; i++){digitalWrite(level[i] , LOW);}
}
void squre_con(){
int delay_time = 300;
int squre_con[2] = {255,255};
value = squre_con[0];
value2= squre_con[1];
writeOutput();
for(int i=4;i>=0;i--){
digitalWrite(level[i], HIGH);
delay(delay_time);
digitalWrite(level[i] , LOW);
}
for(int i=1;i<4;i++){
digitalWrite(level[i], HIGH);
delay(delay_time);
digitalWrite(level[i], LOW);
}
}
void bright_con(){
int delay_time = 5;
int all_ON[2] = {255, 255};
for(int i=0;i<4;i++){digitalWrite(level[i], HIGH);}
value = all_ON[0];
value2= all_ON[1];
writeOutput();
for(int j=0;j<256;j++){
analogWrite(analogOut, j);
Serial.println(j);
delay(delay_time);
}
for(int j=255;j>=0;j--){
analogWrite(analogOut, j);
Serial.println(j);
delay(delay_time);
}
}
void cross_con(){
int delay_time = 300;
int cross_con[2][4][2] = {
{{128,0}, {4,0}, {0, 32}, {0,1}},
{{16,0}, {2,0}, {0,64}, {0,8}}
};
for(int i=0;i<4; i++){
digitalWrite(level[i], HIGH);
digitalWrite(level[3-i], HIGH);
value = cross_con[0][i][0];
value2= cross_con[0][i][1];
writeOutput();
delay(delay_time);
digitalWrite(level[i], LOW);
digitalWrite(level[3-i], LOW);
}
for(int i=2;i>=0;i--){
digitalWrite(level[i], HIGH);
digitalWrite(level[3-i], HIGH);
value = cross_con[0][i][0];
value2= cross_con[0][i][1];
writeOutput();
delay(delay_time);
digitalWrite(level[i], LOW);
digitalWrite(level[3-i], LOW);
}
for(int i=0;i<4; i++){
digitalWrite(level[i], HIGH);
digitalWrite(level[3-i], HIGH);
value = cross_con[1][i][0];
value2= cross_con[1][i][1];
writeOutput();
delay(delay_time);
digitalWrite(level[i], LOW);
digitalWrite(level[3-i], LOW);
}
for(int i=2;i>=0;i--){
digitalWrite(level[i], HIGH);
digitalWrite(level[3-i], HIGH);
value = cross_con[1][i][0];
value2= cross_con[1][i][1];
writeOutput();
delay(delay_time);
digitalWrite(level[i], LOW);
digitalWrite(level[3-i], LOW);
}
}