리듬게임 |
좋아요:0 | ||||
---|---|---|---|---|---|
작성자 | 신동주 | 등록일 | 17.10.21 | 조회수 | 140 |
#include "LedControl.h" #define C 2093 #define Cs 2217 #define D 2349 #define Ds 2489 #define E 2637 #define F 2793 #define Fs 2959 #define G 3135 #define Gs 3322 #define A 3520 #define As 3729 #define B 3951 #define aC 4186 #define aCs 4434 #define aD 4698 #define aDs 4978 #define aE 5274 #define aF 5587 #define aFs 5920 #define aG 6271 #define aGs 6644 #define aA 7040 #define aAs 7458 #define aB 7902 LedControl lc=LedControl(12,11,10,1); int MAP[3][9]={{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}}; int s1[]={C,A,G,F,C,C,A,G,F,D,D,B,A,G,E,aC,aC,B,G,A,F,C,A,G,F,C,C,A,G,F,D,D,B,A,G,aC,aC,aC,aC,aD,aC,A,G,F,A,A,A,A,A,A,A,aC,F,G,A,B,B,B,B,B,A,A,A,A,G,G,F,A,aC,A,A,A,A,A,A,A,aC,F,G,A,B,B,B,B,B,A,A,A,aC,aC,B,G,F}; int r[3][150]= {{0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,1,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1,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,0,0,0,1,0,0,1,0,1,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,1,1,0,1,1,0,0,1,0,1,1,0,0,0,0,0}, {0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,0,0,0,0,1,0,0,1,0,0,1,1,0,0,0,1,0,0,1,0,0,0,0,0,1,1,0,0,0,1,1,1,1,0,0,1,0,1,0,0,0,1,0,0,1,0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,1,1,1,0,0,1,1,0,0,1,0,0,1,0,1,0,0,1,0,0,0,1,1,0,0,0,0,1,1,1,1,0,1,0,0,0,0,1,1,0,0,0,1,0,0,1,0,0,0,1,0,1,0,1,0,1,0,1,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,0,0,1,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,1,0,1,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,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,0,1,1,1,0,1,0,0,1,1,0,1,1,0,0,0,0,0}}; int t=0,l=0,y=0; int prev[3]; void setup() { Serial.begin(9600); lc.shutdown(0,false); lc.setIntensity(0,8); lc.clearDisplay(0); pinMode(7,INPUT_PULLUP); pinMode(6,INPUT_PULLUP); pinMode(5,INPUT_PULLUP); pinMode(8,OUTPUT); } void loop() { int i,j,k,m; for(i=0;i<3;i++) { for(j=1;j<9;j++) { lc.setLed(0,i*3,j-1,MAP[i][j]); lc.setLed(0,i*3+1,j-1,MAP[i][j]); } } lc.setLed(0,0,0,1); lc.setLed(0,1,0,1); lc.setLed(0,3,0,1); lc.setLed(0,4,0,1); lc.setLed(0,6,0,1); lc.setLed(0,7,0,1); if(t%75==0) { for(i=0;i<3;i++) { MAP[i][8]=r[i][y]; } y++; for(i=0;i<3;i++) { for(j=0;j<9;j++) { if(MAP[i][j]==1) { MAP[i][j]=0; if(j>0) { MAP[i][j-1]=1; } else { l++; } } } } } for(k=0;k<3;k++) { if(!digitalRead(5+k) && digitalRead(5+k)!=prev[k]) { delay(5); t+=5; prev[k]=digitalRead(5+k); if(!digitalRead(5+k) && digitalRead(5+k)==prev[k]) { for(m=0;m<2;m++) { if(MAP[k][m]==1) { tone(8,s1[l],100); MAP[k][m]=0; l++; } } } } } prev[0]=digitalRead(5); prev[1]=digitalRead(6); prev[2]=digitalRead(7); t+=5; Serial.println(t); } |
이전글 | 피아노보다 좋은 아두이노 피아노 |
---|---|
다음글 | 탁구공 치기 |