Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void comms(int detectionHash, int groupNumber) {
- bool done = false;
- char incoming;
- unsigned long t = millis();
- int groups[5] = {0};
- char start;
- if(groupNumber == 1){
- start = 'a';
- }
- else if (groupNumber == 2){
- start = 'f';
- }
- else if (groupNumber == 3){
- start = 'k';
- }
- else if (groupNumber == 4){
- start = 'p';
- }
- else if (groupNumber == 5){
- start = 'u';
- }else{
- return;
- }
- int scores[5];
- scores[groupNumber] = detectionHash;
- while (!done) {
- Serial2.println((char)(start + detectionHash - 1));
- if (Serial2.available()) {
- incoming = Serial2.read();
- }
- if (millis() - t > 30000) {
- done = true;//emergency condition
- }
- //decoder
- char input = incoming;
- if (input >= 'a' && input <= 'e') {
- scores[0] = input - 'a' + 1;
- }
- else if (input >= 'f' && input <= 'j') {
- scores[1] = input - 'f' + 1;
- }
- else if (input >= 'k' && input <= 'o') {
- scores[2] = input - 'k' + 1;
- }
- else if (input >= 'p' && input <= 't') {
- scores[3] = input - 'p' + 1;
- }
- else if (input >= 'u' && input <= 'y') {
- scores[4] = input - 'u' + 1;
- }
- if (scores[0] != 0 && scores[1] != -1 && scores[2] != -1 && scores[3] != -1 && scores[4] != -1) {
- done = true;
- }
- }
- int lowest = min(min(min(scores[0], scores[1]), scores[2]), scores[3]);
- if (scores[4] == 5) {
- Serial3.println("Crazy");//go crazy or something
- }
- else if (scores[4] == lowest) {
- Serial3.println("Dino wins");//dino wins
- }
- else if (scores[4] != lowest) {
- Serial3.println("Dino loses");//dino loses
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement