Stap 3: Code
/*
* Arduino knop spel
*
* Ontwikkeld door Mohammed Adil
* B.Tech 3e sem
* Student aan de Universiteit van Lovely Professional
* */
int geleid [5] = {4,5,6,7,8}; LED's voor 1ste speler
int led_1 [5] = {9,10,11,12,13}; //LEDs voor 2de speler
int i = 0;
int j = 0;
int button_1 = 0; //Button input voor speler 1
int button_2 = 0; //Button input voor speler 2
VOID Setup {}
Invoermodus Pin
voor (int thispin = 4; thispin < 14; thispin ++)
{
pinMode(thispin,OUTPUT);
}
Pin uitvoermodus
pinMode(2,INPUT);
pinMode(3,INPUT);
}
void loop
{
BUTTON_1=digitalRead(2); Beginwaarde van het lezen van speler 1
button_2=digitalRead(3); Beginwaarde van het lezen van speler 2
if(Button_1==High) {}
doen
{
digitalWrite(led[i],HIGH);
} while(digitalRead(2)==HIGH);
if(i<4)
{
i ++;
}
anders if(i==4)
{
voor (int thispin = 4; thispin < 9; thispin ++)
{
digitalWrite(thispin,LOW);
}
delay(200);
voor (int thispin = 4; thispin < 9; thispin ++)
{
digitalWrite(thispin,HIGH);
}
delay(200);
voor (int thispin = 4; thispin < 9; thispin ++)
{
digitalWrite(thispin,LOW);
}
delay(200);
voor (int thispin = 4; thispin < 9; thispin ++)
{
digitalWrite(thispin,HIGH);
}
delay(200);
voor (int thispin = 4; thispin < 14; thispin ++)
{
digitalWrite(thispin,LOW);
}
j = 0;
Ik = 0;
}
anders
{
Ik = 0;
}
}
if(button_2==High)
{
doen
{
digitalWrite(led_1[j],HIGH);
} while(digitalRead(3)==HIGH);
if(j<4)
{
j ++;
}
anders if(j==4)
{
voor (int thispin = 9; thispin < 14; thispin ++)
{
digitalWrite(thispin,LOW);
}
delay(200);
voor (int thispin = 9; thispin < 14; thispin ++)
{
digitalWrite(thispin,HIGH);
}
delay(200);
voor (int thispin = 9; thispin < 14; thispin ++)
{
digitalWrite(thispin,LOW);
}
delay(200);
voor (int thispin = 9; thispin < 14; thispin ++)
{
digitalWrite(thispin,HIGH);
}
delay(200);
voor (int thispin = 4; thispin < 14; thispin ++)
{
digitalWrite(thispin,LOW);
}
Ik = 0;
j = 0;
}
anders
{
j = 0;
}
}
}