countdown
//https://m.blog.naver.com/eduino/221130299439 #include<FrequencyTimer2.h> #define ZERO{\ {0,0,0,1,1,0,0,0}, \ {0,0,1,0,0,1,0,0}, \ {0,0,1,0,0,1,0,0}, \ {0,0,1,0,0,1,0,0}, \ {0,0,1,0,0,1,0,0}, \ {0,0,1,0,0,1,0,0}, \ {0,0,1,0,0,1,0,0}, \ {0,0,0,1,1,0,0,0} \ } #define ONE{ \ {0,0,0,0,1,0,0,0}, \ {0,0,0,1,1,0,0,0}, \ {0,0,0,0,1,0,0,0}, \ {0,0,0,0,1,0,0,0}, \ {0,0,0,0,1,0,0,0}, \ {0,0,0,0,1,0,0,0}, \ {0,0,0,0,1,0,0,0}, \ {0,0,0,1,1,1,0,0} \ } #define TWO{ \ {0,0,0,1,1,0,0,0}, \ {0,0,1,0,0,1,0,0}, \ {0,0,1,0,0,1,0,0}, \ {0,0,0,0,0,1,0,0}, \ {0,0,0,0,1,0,0,0}, \ {0,0,0,1,0,0,0,0}, \ {0,0,1,0,0,0,0,0}, \ {0,0,1,1,1,1,0,0} \ } ///2 #define THREE{ \ {0,0,0,1,1,0,0,0}, \ {0,0,1,0,0,1,0,0}, \ {0,0,1,0,0,1,0,0}, \ {0,0,0,0,1,0,0,0}, \ {0,0,0,0,0,1,0,0}, \ {0,0,1,0,0,1,0,0}, \ {0,0,1,0,0,1,0,0}, \ {0,0,0,1,1,0,0,0} \ } #define FOUR{ \ {0,0,1,0,0,1,0,0}, \ {0,0,1,0,0,1,0,0}, \ {0,0,1,0,0,1,0,0}, \ {0,0,0,1,1,1,0,0}, \ {0,0,0,0,0,1,0,0}, \ {0,0,0,0,0,1,0,0}, \ {0,0,0,0,0,1,0,0}, \ {0,0,0,0,0,1,0,0} \ } #define FIVE{ \ {0,0,1,1,1,1,0,0}, \ {0,0,1,0,0,0,0,0}, \ {0,0,1,0,0,0,0,0}, \ {0,0,1,1,1,0,0,0}, \ {0,0,0,0,0,1,0,0}, \ {0,0,0,0,0,1,0,0}, \ {0,0,0,0,0,1,0,0}, \ {0,0,1,1,1,0,0,0} \ } #define SIX{ \ {0,0,0,1,1,0,0,0}, \ {0,0,1,0,0,1,0,0}, \ {0,0,1,0,0,0,0,0}, \ {0,0,1,1,1,0,0,0}, \ {0,0,1,0,0,1,0,0}, \ {0,0,1,0,0,1,0,0}, \ {0,0,1,0,0,1,0,0}, \ {0,0,0,1,1,0,0,0} \ } #define SEVEN{ \ {0,0,1,1,1,1,0,0}, \ {0,0,1,0,0,1,0,0}, \ {0,0,1,0,0,1,0,0}, \ {0,0,0,0,0,1,0,0}, \ {0,0,0,0,0,1,0,0}, \ {0,0,0,0,0,1,0,0}, \ {0,0,0,0,0,1,0,0}, \ {0,0,0,0,0,1,0,0} \ } #define EIGHT{ \ {0,0,0,1,1,0,0,0}, \ {0,0,1,0,0,1,0,0}, \ {0,0,1,0,0,1,0,0}, \ {0,0,0,1,1,0,0,0}, \ {0,0,1,0,0,1,0,0}, \ {0,0,1,0,0,1,0,0}, \ {0,0,1,0,0,1,0,0}, \ {0,0,0,1,1,0,0,0} \ } #define NINE{ \ {0,0,0,1,1,0,0,0}, \ {0,0,1,0,0,1,0,0}, \ {0,0,1,0,0,1,0,0}, \ {0,0,0,1,1,1,0,0}, \ {0,0,0,0,0,1,0,0}, \ {0,0,0,0,0,1,0,0}, \ {0,0,0,0,0,1,0,0}, \ {0,0,0,0,0,1,0,0} \ } byte col = 0; byte leds[8][8]; int pins[17] = {-1,5,4,3,2,14,15,16,17,13,12,11,10,9,8,7,6}; int cols[8] = {pins[13], pins[3], pins[4], pins[10], pins[6], pins[11], pins[15], pins[16]}; int rows[8] = {pins[9], pins[14], pins[8], pins[12], pins[1], pins[7], pins[2], pins[5]}; const int numPatterns = 10; byte patterns[numPatterns][8][8] = {ZERO, ONE,TWO,THREE, FOUR, FIVE,SIX, SEVEN, EIGHT, NINE}; int pattern = 0; void setup() { pattern = numPatterns-1; for(int i = 1;i<=16;i++) { pinMode(pins[i], OUTPUT); } for(int i = 0;i<8;i++) { digitalWrite(cols[i], HIGH); } for(int i = 0;i<8;i++) { digitalWrite(rows[i], HIGH); } clearLeds(); FrequencyTimer2::setOnOverflow(display); setPattern(pattern); } void loop() { delay(1000); pattern--; if(pattern==-1) { pattern = numPatterns-1; } setPattern(pattern); } void clearLeds() { for(int i = 0;i<8;i++) { for(int j = 0;j<8;j++) { leds[i][j] = 0; } } } void setPattern(int pattern) { for(int i = 0;i<8;i++) { for(int j = 0;j<8;j++) { leds[i][j] = patterns[pattern][i][j]; } } } void display() { digitalWrite(cols[col], HIGH); col++; if(col==8) { col=0; } for(int row = 0;row<=7;row++) { if(leds[col][7-row]==1) { digitalWrite(rows[row], HIGH); } else { digitalWrite(rows[row], LOW); } } digitalWrite(cols[col], LOW); }
joy stick #include<FrequencyTimer2.h> byte col = 0; byte leds[8][8]; int pins[17] = {-1,5,4,3,2,14,15,16,17,13,12,11,10,9,8,7,6}; int cols[8] = {pins[13], pins[3], pins[4], pins[10], pins[6], pins[11], pins[15], pins[16]}; int rows[8] = {pins[9], pins[14], pins[8], pins[12], pins[1], pins[7], pins[2], pins[5]}; int x = 4; int y = 4; void setup() { Serial.begin(9600); for(int i = 1;i<=16;i++) { pinMode(pins[i], OUTPUT); } for(int i = 0;i<8;i++) { digitalWrite(cols[i], HIGH); } for(int i = 0;i<8;i++) { digitalWrite(rows[i], HIGH); } updateLeds(); FrequencyTimer2::setOnOverflow(display); } void loop() { int val_0 = analogRead(A4); int val_1 = analogRead(A5); bool a = false; if(val_0<300){ if(x<7) { x+=1; a=true; } } else if(val_0>700) { if(x>0) { x-=1; a=true; } } if(val_1<300) { if(y<7) { y+=1; a=true; } } else if(val_1>700) { if(y>0) { y-=1; a=true; } } updateLeds(); if(a==true) { delay(500); } } void updateLeds() { for(int i = 0;i<8;i++) { for(int j = 0;j<8;j++) { leds[i][j] = 0; } } leds[y][x] = 1; } void display() { digitalWrite(cols[col], HIGH); col++; if(col==8) { col=0; } for(int row = 0;row<=7;row++) { if(leds[col][7-row]==1) { digitalWrite(rows[row], HIGH); } else { digitalWrite(rows[row], LOW); } } digitalWrite(cols[col], LOW); }