Étape 3: Code
/*
* Jeu de bouton Arduino
*
* Développé par Mohammed Adil
* B.Tech 3ème sem
* Étudiant à l’Université de Lovely Professional
* */
int a conduit [5] = {4,5,6,7,8} ; 1er lecteur par LED
int led_1 [5] = {9,10,11,12,13}; //LEDs pour le 2e joueur
int i = 0 ;
int j = 0 ;
int button_1 = 0; //Button entrée pour lecteur 1
int button_2 = 0; //Button entrée pour lecteur 2
void setup() {}
Mode d’entrée de Pin
pour (int thispin = 4; thispin < 14 ; thispin ++)
{
pinMode(thispin,OUTPUT) ;
}
Mode de broche de sortie
pinMode(2,INPUT) ;
pinMode(3,INPUT) ;
}
void loop()
{
button_1=digitalRead(2) ; Lire la valeur initiale du joueur 1
button_2=digitalRead(3) ; Lire la valeur initiale du joueur 2
{if(button_1==High)}
faire
{
digitalWrite(led[i],HIGH) ;
} while(digitalRead(2)==HIGH) ;
if(i<4)
{
i ++ ;
}
d’autre if(i==4)
{
pour (int thispin = 4; thispin < 9; thispin ++)
{
digitalWrite(thispin,LOW) ;
}
Delay(200) ;
pour (int thispin = 4; thispin < 9; thispin ++)
{
digitalWrite(thispin,HIGH) ;
}
Delay(200) ;
pour (int thispin = 4; thispin < 9; thispin ++)
{
digitalWrite(thispin,LOW) ;
}
Delay(200) ;
pour (int thispin = 4; thispin < 9; thispin ++)
{
digitalWrite(thispin,HIGH) ;
}
Delay(200) ;
pour (int thispin = 4; thispin < 14 ; thispin ++)
{
digitalWrite(thispin,LOW) ;
}
j = 0 ;
i = 0 ;
}
d’autre
{
i = 0 ;
}
}
if(button_2==High)
{
faire
{
digitalWrite(led_1[j],HIGH) ;
} while(digitalRead(3)==HIGH) ;
if(j<4)
{
j ++ ;
}
d’autre if(j==4)
{
pour (int thispin = 9; thispin < 14 ; thispin ++)
{
digitalWrite(thispin,LOW) ;
}
Delay(200) ;
pour (int thispin = 9; thispin < 14 ; thispin ++)
{
digitalWrite(thispin,HIGH) ;
}
Delay(200) ;
pour (int thispin = 9; thispin < 14 ; thispin ++)
{
digitalWrite(thispin,LOW) ;
}
Delay(200) ;
pour (int thispin = 9; thispin < 14 ; thispin ++)
{
digitalWrite(thispin,HIGH) ;
}
Delay(200) ;
pour (int thispin = 4; thispin < 14 ; thispin ++)
{
digitalWrite(thispin,LOW) ;
}
i = 0 ;
j = 0 ;
}
d’autre
{
j = 0 ;
}
}
}