Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. void comms(int detectionHash, int groupNumber) {
  2. bool done = false;
  3. char incoming;
  4. unsigned long t = millis();
  5. int groups[5] = {0};
  6.  
  7. char start;
  8.  
  9. if(groupNumber == 1){
  10. start = 'a';
  11. }
  12. else if (groupNumber == 2){
  13. start = 'f';
  14. }
  15. else if (groupNumber == 3){
  16. start = 'k';
  17. }
  18. else if (groupNumber == 4){
  19. start = 'p';
  20. }
  21. else if (groupNumber == 5){
  22. start = 'u';
  23. }else{
  24. return;
  25. }
  26.  
  27. int scores[5];
  28. scores[groupNumber] = detectionHash;
  29. while (!done) {
  30. Serial2.println((char)(start + detectionHash - 1));
  31. if (Serial2.available()) {
  32. incoming = Serial2.read();
  33. }
  34. if (millis() - t > 30000) {
  35. done = true;//emergency condition
  36. }
  37. //decoder
  38. char input = incoming;
  39. if (input >= 'a' && input <= 'e') {
  40. scores[0] = input - 'a' + 1;
  41. }
  42. else if (input >= 'f' && input <= 'j') {
  43. scores[1] = input - 'f' + 1;
  44. }
  45. else if (input >= 'k' && input <= 'o') {
  46. scores[2] = input - 'k' + 1;
  47. }
  48. else if (input >= 'p' && input <= 't') {
  49. scores[3] = input - 'p' + 1;
  50. }
  51. else if (input >= 'u' && input <= 'y') {
  52. scores[4] = input - 'u' + 1;
  53. }
  54.  
  55. if (scores[0] != 0 && scores[1] != -1 && scores[2] != -1 && scores[3] != -1 && scores[4] != -1) {
  56. done = true;
  57. }
  58. }
  59.  
  60. int lowest = min(min(min(scores[0], scores[1]), scores[2]), scores[3]);
  61.  
  62. if (scores[4] == 5) {
  63. Serial3.println("Crazy");//go crazy or something
  64. }
  65. else if (scores[4] == lowest) {
  66. Serial3.println("Dino wins");//dino wins
  67. }
  68. else if (scores[4] != lowest) {
  69. Serial3.println("Dino loses");//dino loses
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement