i tried using atoi() to convert the string s1,s2,s3 but it returns 24,25,19. which doesn't make sense in my sorting.
here's what i've been working...it stores time for every player, and displays their time at the end of the program, but i wanted to sort the data "m:sec:mm" from highest to lowest then display who has the slowest time to the fastest time.
#include <LiquidCrystal.h> //LCD library
LiquidCrystal lcd(3, 5, 9, 10, 11, 12); //LCD Pin initialization
int numPlayer = 0; //variable for number of player
int i = 0; //incrementing variable for saving to array record
void setup() {
lcd.begin(16,2); //sets the display to have 16x2 display
pinMode(6, INPUT); //pin 6 input
pinMode(7, INPUT); //pin 7 input
}
void loop(){
while (digitalRead(7) == HIGH){ //while pin 7 is high ask for number of players
lcd.setCursor(0, 0); //sets the cursor of the LCD display to 0,0
lcd.print("# of Players"); //prints the "# of players" on the LCD display
if (digitalRead(6) == LOW){ //when pin 6 is press do numplayer++
numPlayer++; //increment the number of player
delay(500); //set delay so that pressing 6 will ensure +1 increment
}
lcd.setCursor(0, 1); //sets the cursor of the LCD display to 0,1
lcd.print(numPlayer); //prints the value of numPlayer on the LCD display
}
int mmRecord[numPlayer]; //create array with size of numplayer
int secRecord[numPlayer]; //create array with size of numplayer
int mRecord[numPlayer]; //create array with size of numplayer
timeStart: //label where the time starts
lcd.clear(); //clears the display
lcd.setCursor(7, 0); //sets the cursor of the LCD display to 0,1
lcd.print("Lap Time:"); //prints the "Lap Time:" on the LCD display
for (int m = 0; m < 60; ++m) { //minute is initially 0 and increments until m is 60 or greater
for (int sec = 0; sec < 60; ++sec) { //second is initially 0 and increments until sec is 60 or greater
for (int mm = 0; mm < 100; ++mm) { //milli is initially 0 and increments until mm is 100 or greater
display_LCD(m,sec,mm); //call function display_LCD()
delay(10); //set delay(10)
if (digitalRead(6) == LOW){ //when pressed have to mm,sec,m arrays
if ( i != numPlayer){ //condition when i is not equal to numplayer do commands below
mmRecord[i] = mm; //mm array
secRecord[i] = sec; //sec array
mRecord[i] = m; //m array
i++; //i increment
lcd.clear(); //clear LCD
while (digitalRead(7) == HIGH){ //while pin 7 is high do commands below
lcd.setCursor(0, 0);
lcd.print("Click button 2");
lcd.setCursor(0, 1);
lcd.print("to Start Next");
delay(100);
}
goto timeStart;
}
}
if ( i == numPlayer){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Game Finish");
lcd.setCursor(0, 1);
lcd.print("Time Recap");
delay(2000);
for (int j = 0 ; j < i ; j++) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Player");
lcd.setCursor(7, 0);
lcd.print(j+1); //displays Player #
display_LCD(mRecord[j],secRecord[j],mmRecord[j]); //display time for Player #
delay(3000);
}
}
}
}
}
}
}
void display_LCD(int m, int sec, int mm){ //create function for printing m:sec:mm format
char s[10]; //array for character number for m:sec:mm
sprintf(s, "%02d:%02d:%02d", m, sec, mm); //put m,sec,mm value to s with formating of m:sec:mm
lcd.setCursor(8, 1); //sets the cursor of the LCD display to 8,1
lcd.print(s); //prints the value of s on the LCD display
}