//press 2nd switch glow the leds as per the given questions
void setup() {
// put your setup code here, to run once:
volatile char *outf,*dirf,*dirk,*ink,x,y,z,s,r;
volatile long i,j;
dirf=0x30;
*dirf=0xff;
dirk=0x107;
*dirk=0x00;
outf=0x31;
ink=0x106;
while(1){
x = *ink;
y= *ink;
z= *ink;
int count =0;
if((z & 0x04) !=0){
count++;
for(i=0;i<100000;i++);
*outf=0x02;
for(i=0;i<100000;i++);
*outf=0x04;
for(i=0;i<100000;i++);
*outf=0x20;
for(i=0;i<100000;i++);
*outf=0x40;
for(i=0;i<100000;i++);
}
if((x & 0x08)!=0){
for(i=0;i<100000;i++);
*outf=0x04;
for(i=0;i<100000;i++);
*outf=0x02;
for(i=0;i<100000;i++);
*outf=0x80;
for(i=0;i<100000;i++);
*outf=0x10;
for(i=0;i<100000;i++);
}
while((x & 0x04 )!=0){
if(count!=0){
for(i=0;i<100000;i++);
*outf=0x01;
for(i=0;i<100000;i++);
*outf=0x02;
for(i=0;i<100000;i++);
*outf=0x20;
for(i=0;i<100000;i++);
*outf=0x40;
for(i=0;i<100000;i++);
}
}
}
}