Commit a9f72d97 authored by Václav Aubrecht's avatar Václav Aubrecht
Browse files

Update FW/WhoFirst/whofirst.ino

parent 69379053
// Who First 2.0 selftest
// written by @oktkas
// Who First 2.0 working programme
//Written by @vashkos
// press all the buttons to test out your soldering job
// all LEDs must turn white
// set pins for RGB color control
#define R 8
......@@ -44,13 +42,9 @@ void loop() {
int lBTNs[4];
for (int i=0; i <4; i++){
lBTNs[i]=digitalRead(BTNs[i]);
Serial.println(lBTNs[i]);
//Serial.println(lBTNs[i]);
}
//Serial.println(lBTNs[0]);
//Serial.println(lBTNs[1]);
//Serial.println(lBTNs[2]);
//Serial.println(lBTNs[3]);
if (lBTNs[0]+lBTNs[1]+lBTNs[2]+lBTNs[3]==0) {
for (int rounds=0; rounds<10; rounds++){
game();
......@@ -58,15 +52,11 @@ if (lBTNs[0]+lBTNs[1]+lBTNs[2]+lBTNs[3]==0) {
//Write out the current state of points
for (int i=0; i < 4; i++) {
Serial.println(players[i]);
}
}
}
podium();
}
}
void homescreen () {
......@@ -95,12 +85,28 @@ void game() {
digitalWrite(LEDs[i], HIGH);
}
delay(100);
//game start
digitalWrite(R, HIGH);
digitalWrite(G, HIGH);
digitalWrite(B, LOW);
//Chooses a random delay between 500 and 5000 milliseconds.
int randomtime=random(500, 5000);
//game start, picks a random color
bool red_var;
bool green_var;
bool blue_var;
//Creates a loop that repeats until the total of the booleans isn't zero. Used for at least one color to turn on.
for (int i =0; i<2; i=0){
red_var = random(0,2);
green_var = random(0,2);
blue_var = random(0,2);
//Serial.println(red_var);
//Serial.println(green_var);
//Serial.println(blue_var);
if (red_var + green_var + blue_var !=0){
break;
i=2;
}
}
digitalWrite(R, red_var);
digitalWrite(G, green_var);
digitalWrite(B, blue_var);
//Chooses a random delay between 1000 and 8000 milliseconds.
int randomtime=random(1000, 8000);
delay(randomtime);
//turns on all LEDs
for (int i=0; i < 4; i++) {
......@@ -108,7 +114,7 @@ delay(randomtime);
}
//Checks 1500 times if one of the buttons has been pressed.
for (int i=0; i<1500; i++){
Serial.println("check");
//Serial.println("check");
for (int y=0; y<4; y++){
bool x= digitalRead(BTNs[y]);
......@@ -132,3 +138,35 @@ for (int i=0; i<1500; i++){
}
}
void podium(){
digitalWrite(R, LOW);
digitalWrite(G, HIGH);
digitalWrite(B, LOW);
int most_points =max(max(max(players[3], players[2]), players[1]), players[0]);//Tells the largest amount of points.
for(int i =0; i<4; i++){//Assigns ones to players with most points (there can be more 1st places), assigns zeros to everyone else.
if(players[i]==most_points){
players[i]=1;
}
else{
players[i]=0;
}
}
for (int i=0; i < 4; i++) {
Serial.println(players[i]);
digitalWrite(LEDs[i], HIGH);
}
for(int i=0; i<4; i++){//Turns LEDs for players with ones.
if(players[i]==1){
digitalWrite(LEDs[i], LOW);
}
else{
digitalWrite(LEDs[i], HIGH);
}
}
delay(5000);
for(int i=0; i<4; i++){//Nulls the points
players[i] =0;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment