Вы находитесь на странице: 1из 3

digitalWrite(col[colVal8],1);}

CODE 6
int col[5]={2,3,4,5,6},row[8]={7,8,9,10,11,12,13,14};
int colGr[5]={15,16,17,18,19};
int delayVal = 3, delayDown = 1000;
unsigned long int prevMillis=0;
void setup()
{
for(int i=0;i<=4;i++)
{
pinMode(col[i],OUTPUT);
pinMode(colGr[i],OUTPUT);
}
for(int j=0;j<=7;j++) pinMode(row[j],OUTPUT);
randomSeed(analogRead(0));
// Serial.begin(9600);//testing purposes
}
void loop()
{
run();
}
void run()
{
for(int d=0;d<=20;d++){
resetAll();
unsigned int colVal=random(0,4);
unsigned int colVal2=random(0,4);
unsigned int colVal3=random(0,4);
unsigned int colVal4=random(0,4);
unsigned int colVal5=random(0,4);
unsigned int colVal6=random(0,4);
unsigned int colVal7=random(0,4);
unsigned int colVal8=random(0,4);
int j=7;
while(j>=-7)
{unsigned long int currentMillis=millis(); if ( currentMillis - prevMillis
> delayDown ) { prevMillis = currentMillis; j--; }
{
if( j<=7 && j>=0){
digitalWrite(row[j],1);
digitalWrite(col[colVal],0);
delay(delayVal);
digitalWrite(row[j],0);
digitalWrite(col[colVal],1);}

if( j<=6 && j>=-1){


digitalWrite(row[j+1],1);
digitalWrite(col[colVal2],0);
delay(delayVal);
digitalWrite(row[j+1],0);
digitalWrite(col[colVal2],1);}
if( j<=5 && j>=-2){
digitalWrite(row[j+2],1);
digitalWrite(col[colVal3],0);
delay(delayVal);
digitalWrite(row[j+2],0);
digitalWrite(col[colVal3],1);}
if( j<=4 && j>=-3){
digitalWrite(row[j+3],1);
digitalWrite(col[colVal4],0);
delay(delayVal);
digitalWrite(row[j+3],0);
digitalWrite(col[colVal4],1);}
if( j<=3 && j>=-4){
digitalWrite(row[j+4],1);
digitalWrite(col[colVal5],0);
delay(delayVal);
digitalWrite(row[j+4],0);
digitalWrite(col[colVal5],1);}
if( j<=2 && j>=-5){
digitalWrite(row[j+5],1);
digitalWrite(col[colVal6],0);
delay(delayVal);
digitalWrite(row[j+5],0);
digitalWrite(col[colVal6],1);}
if( j<=1 && j>=-6){
digitalWrite(row[j+6],1);
digitalWrite(col[colVal7],0);
delay(delayVal);
digitalWrite(row[j+6],0);
digitalWrite(col[colVal7],1);}
if( j<=0 && j>=-7){
digitalWrite(row[j+7],1);
digitalWrite(col[colVal8],0);
delay(delayVal);
digitalWrite(row[j+7],0);

}
} //close for
}
}
void lightsAll() //ilaw lahat
{
for(int i=0;i<=4;i++)
{
digitalWrite(col[i],0);
digitalWrite(colGr[i],0);
}
for(int j=0;j<=7;j++) digitalWrite(row[j],1);
}
void resetAll() //wala ilaw lahat
{
for(int i=0;i<=4;i++)
{
digitalWrite(col[i],1);
digitalWrite(colGr[i],1);
}
for(int j=0;j<=7;j++) digitalWrite(row[j],0);
}
int col[5]={2,3,4,5,6},row[8]={7,8,9,10,11,12,13,14};
int swx[4]={16,17,18,19};
int delayVal = 3, delayDown = 1000;
int score = 0;
unsigned long int prevMillis=0;
void setup()
{
for(int i=0;i<=4;i++)
{
pinMode(col[i],OUTPUT);
pinMode(swx[i],INPUT);
}
for(int j=0;j<=7;j++) pinMode(row[j],OUTPUT);
pinMode(15,OUTPUT);
randomSeed(analogRead(0));
Serial.begin(9600);//testing purposes
}
void loop()
{

if(digitalRead(swx[0])==1 || digitalRead(swx[0])==1)
{Serial.println("*************** L E V E L 1 ****************");
run();}
else
lightsAll();delay(100);resetAll();delay(100);
}

void run()
{
for(int d=0;d<=20;d++){
resetAll();
unsigned int colVal=random(0,4);
unsigned int colVal2=random(0,4);
unsigned int colVal3=random(0,4);
unsigned int colVal4=random(0,4);
unsigned int colVal5=random(0,4);
unsigned int colVal6=random(0,4);
unsigned int colVal7=random(0,4);
unsigned int colVal8=random(0,4);
int j=7;
while(j>=-7)
{unsigned long int currentMillis=millis(); if ( currentMillis - prevMillis
> delayDown ) { prevMillis = currentMillis; j--; }
{
if( j<=7 && j>=0){
digitalWrite(row[j],1);
digitalWrite(col[colVal],0);
delay(delayVal);
digitalWrite(row[j],0);
digitalWrite(col[colVal],1);
if(row[0]==1 && col[colVal]==0 && swx[colVal]!=1) return;}
if( j<=6 && j>=-1){
digitalWrite(row[j+1],1);
digitalWrite(col[colVal2],0);
delay(delayVal);
digitalWrite(row[j+1],0);
digitalWrite(col[colVal2],1);
scorer(colVal2);}
if( j<=5 && j>=-2){
digitalWrite(row[j+2],1);
digitalWrite(col[colVal3],0);
delay(delayVal);
digitalWrite(row[j+2],0);
digitalWrite(col[colVal3],1);}

scorer(colVal3);
if( j<=4 && j>=-3){
digitalWrite(row[j+3],1);
digitalWrite(col[colVal4],0);
delay(delayVal);
digitalWrite(row[j+3],0);
digitalWrite(col[colVal4],1);}
scorer(colVal4);
if( j<=3 && j>=-4){
digitalWrite(row[j+4],1);
digitalWrite(col[colVal5],0);
delay(delayVal);
digitalWrite(row[j+4],0);
digitalWrite(col[colVal5],1);}
scorer(colVal5);
if( j<=2 && j>=-5){
digitalWrite(row[j+5],1);
digitalWrite(col[colVal6],0);
delay(delayVal);
digitalWrite(row[j+5],0);
digitalWrite(col[colVal6],1);}
scorer(colVal6);
if( j<=1 && j>=-6){
digitalWrite(row[j+6],1);
digitalWrite(col[colVal7],0);
delay(delayVal);
digitalWrite(row[j+6],0);
digitalWrite(col[colVal7],1);}
scorer(colVal7);
if( j<=0 && j>=-7){
digitalWrite(row[j+7],1);
digitalWrite(col[colVal8],0);
delay(delayVal);
digitalWrite(row[j+7],0);
digitalWrite(col[colVal8],1);}
scorer(colVal8);
//delayDown-=1;
//Serial.print("Your Score : ");Serial.println(score);
}
}
//close for
if(delayDown>500)
delayDown-=100;
if(delayDown<=500 && delayDown>100)

delayDown-=50;
if(delayDown<=100)
delayDown-=5;
if(delayDown==900) Serial.println("*************** L E V E L 2
****************");
if(delayDown==800) Serial.println("*************** L E V E L 3
****************");
if(delayDown==700) Serial.println("*************** L E V E L 4
****************");
if(delayDown==600) Serial.println("*************** L E V E L 5
****************");
if(delayDown==400) Serial.println("*************** L E V E L 6
****************");
if(delayDown==350) Serial.println("*************** L E V E L 7
****************");
if(delayDown==300) Serial.println("*************** L E V E L 8
****************");
if(delayDown==250) Serial.println("*************** L E V E L 9
***************");
if(delayDown==200) Serial.println("*************** L E V E L 10
***************");
if(delayDown==150) Serial.println("*************** L E V E L 11
***************");
if(delayDown==95) Serial.println("*************** L E V E L 12
***************");
if(delayDown==90) Serial.println("*************** L E V E L 13
***************");
if(delayDown==85) Serial.println("*************** L E V E L 14
***************");
if(delayDown==80) Serial.println("*************** L E V E L 15
***************");
if(delayDown==75) Serial.println("*************** L E V E L 16
***************");
if(delayDown==70) Serial.println("*************** L E V E L 17
***************");
if(delayDown==65) Serial.println("*************** L E V E L 18
***************");
if(delayDown==60) Serial.println("*************** L E V E L 19
***************");
if(delayDown==55) Serial.println("*************** L E V E L 20
***************");
if(delayDown==50) Serial.println("**********E X T R E M E L E V E L
*********");
//else if
}
}
void lightsAll() //ilaw lahat

{
for(int i=0;i<=4;i++)
{
digitalWrite(col[i],0);
}
for(int j=0;j<=7;j++) digitalWrite(row[j],1);
}
void resetAll() //wala ilaw lahat
{
for(int i=0;i<=4;i++)
{
digitalWrite(col[i],1);
}
for(int j=0;j<=7;j++) digitalWrite(row[j],0);
}
void scorer(int rnVal)
{
if(row[0]==1 && col[rnVal]==0 && swx[rnVal]==1)
{
score++;
}
}