Arduino knapp spel (3 / 4 steg)
Steg 3: kod
/*
* Arduino knapp spel
*
* Utvecklat av Mohammed Adil
* B.Tech 3. sem
* Student vid vackra Professional universitet
* */
int ledde [5] = {4,5,6,7,8}. Lysdioder för 1 spelare
int led_1 [5] = {9,10,11,12,13}; //LEDs för 2: a spelaren
int jag = 0;
int j = 0;
int button_1 = 0; //Button ingång för spelare 1
int button_2 = 0; //Button ingång för spelare 2
void setup() {
Ingångsläge för Pin
för (int thispin = 4; thispin < 14; thispin ++)
{
pinMode(thispin,OUTPUT);
}
Pin utmatningsläge
pinMode(2,INPUT);
pinMode(3,INPUT);
}
void loop()
{
button_1=digitalRead(2); Läs ursprungliga värdet för spelare 1
button_2=digitalRead(3); Läs ursprungliga värdet för spelare 2
IF(button_1==High) {
göra
{
digitalWrite(led[i],HIGH);
} while(digitalRead(2)==HIGH);
IF(i<4)
{
i ++;
}
annat if(i==4)
{
för (int thispin = 4; thispin < 9; thispin ++)
{
digitalWrite(thispin,LOW);
}
Delay(200);
för (int thispin = 4; thispin < 9; thispin ++)
{
digitalWrite(thispin,HIGH);
}
Delay(200);
för (int thispin = 4; thispin < 9; thispin ++)
{
digitalWrite(thispin,LOW);
}
Delay(200);
för (int thispin = 4; thispin < 9; thispin ++)
{
digitalWrite(thispin,HIGH);
}
Delay(200);
för (int thispin = 4; thispin < 14; thispin ++)
{
digitalWrite(thispin,LOW);
}
j = 0;
Jag = 0;
}
annat
{
Jag = 0;
}
}
IF(button_2==High)
{
göra
{
digitalWrite(led_1[j],HIGH);
} while(digitalRead(3)==HIGH);
IF(j<4)
{
j ++;
}
annat if(j==4)
{
för (int thispin = 9; thispin < 14; thispin ++)
{
digitalWrite(thispin,LOW);
}
Delay(200);
för (int thispin = 9; thispin < 14; thispin ++)
{
digitalWrite(thispin,HIGH);
}
Delay(200);
för (int thispin = 9; thispin < 14; thispin ++)
{
digitalWrite(thispin,LOW);
}
Delay(200);
för (int thispin = 9; thispin < 14; thispin ++)
{
digitalWrite(thispin,HIGH);
}
Delay(200);
för (int thispin = 4; thispin < 14; thispin ++)
{
digitalWrite(thispin,LOW);
}
Jag = 0;
j = 0;
}
annat
{
j = 0;
}
}
}