Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2. LiquidCrystal lcd(8,9,4,5,6,7);
  3. void setup() {
  4. lcd.begin(16,2);
  5. }
  6.  
  7. bool tura, stop;
  8. int j, ana, wybor = 1, kostka, wynik_1, wynik_2, ilosc_tur = 3;
  9.  
  10. //analog
  11. int v1 = 75, v2 = 200, v3 = 400 , v4 = 600, v5 = 800;
  12.  
  13. void loop() {
  14. //menu
  15. lcd.clear();
  16. ana = analogRead(A0);
  17. lcd.setCursor(0,0);
  18. lcd.print("Wybierz");
  19. lcd.setCursor(0,1);
  20. if (wybor == 1){
  21. lcd.print("Wyrzuc wiecej");
  22. }
  23. else if (wybor == 2) {
  24. lcd.print("Hello there");
  25. }
  26. else{
  27. lcd.print("General Kenobi");
  28. }
  29. if (ana < v1) {
  30. //right
  31. //zmienia gre
  32. wybor++;
  33. if (wybor == 4){
  34. wybor = 1;
  35. }
  36. }
  37. else if (ana > v1 && ana < v2){
  38. //up
  39. //zmienia ilosc tur
  40. ilosc_tur++;
  41. if (ilosc_tur > 10){
  42. ilosc_tur = 10;
  43. }
  44. lcd.clear();
  45. lcd.setCursor(0,0);
  46. lcd.print("Tury");
  47. lcd.setCursor(0,1);
  48. lcd.print(ilosc_tur);
  49. delay(300);
  50. }
  51. else if (ana > v2 && ana < v3){
  52. //down
  53. //zmienia ilosc tur
  54. ilosc_tur--;
  55. if (ilosc_tur < 1){
  56. ilosc_tur = 1;
  57. }
  58. lcd.clear();
  59. lcd.setCursor(0,0);
  60. lcd.print("Tury");
  61. lcd.setCursor(0,1);
  62. lcd.print(ilosc_tur);
  63. delay(300);
  64. }
  65. else if (ana > v3 && ana < v4){
  66. //left
  67. //zmienia gre
  68. wybor--;
  69. if (wybor == 0){
  70. wybor = 3;
  71. }
  72. }
  73. else if (ana > v4 && ana < v5){
  74. //select
  75. //potwierdza wybor
  76. if (wybor == 1){
  77. delay(200);
  78. gra_1();
  79. }
  80. else if (wybor == 2) {
  81. delay(200);
  82. gra_2();
  83. }
  84. else{
  85. delay(200);
  86. gra_3();
  87. }
  88. }
  89. delay(300);
  90. }
  91.  
  92. //wyrzuc wiecej
  93. void gra_1(){
  94. wynik_1 = 0;
  95. wynik_2 = 0;
  96. tura = true;
  97. j = ilosc_tur * 2;
  98. for (int i = 0; i < j; i++){
  99. //gra
  100. lcd.setCursor(0,0);
  101. if (tura == true){
  102. //tura gracza 1
  103. lcd.clear();
  104. lcd.print("Gracz 1");
  105. lcd.setCursor(14,0);
  106. lcd.print(wynik_1);
  107. }
  108. else{
  109. //tura gracza 2
  110. lcd.clear();
  111. lcd.print("Gracz 2");
  112. lcd.setCursor(14,0);
  113. lcd.print(wynik_2);
  114. }
  115. stop = false;
  116. while (stop != true){
  117. //rzut kostka
  118. kostka = random (1,6);
  119. lcd.setCursor(2,1);
  120. lcd.print(kostka);
  121. ana = analogRead(A0);
  122. if (ana > v4 && ana < v5){
  123. //select
  124. stop = true;
  125. }
  126. delay(100);
  127. }
  128. if (tura == true){
  129. wynik_1 = wynik_1 + kostka;
  130. tura = false;
  131. }
  132. else{
  133. wynik_2 = wynik_2 + kostka;
  134. tura = true;
  135. }
  136. delay(2000);
  137. }
  138. //wyniki
  139. lcd.clear();
  140. lcd.setCursor(0,0);
  141. lcd.print("Gracz 1: ");
  142. lcd.print(wynik_1);
  143. lcd.setCursor(0,1);
  144. lcd.print("Gracz 2: ");
  145. lcd.print(wynik_2);
  146. delay(3000);
  147. lcd.clear();
  148. lcd.setCursor(0,0);
  149. if (wynik_1 == wynik_2){
  150. lcd.print("Remis");
  151. }
  152. else if(wynik_1 > wynik_2){
  153. lcd.print("Gracz 1 wygral");
  154. }
  155. else{
  156. lcd.print("Gracz 2 wygral");
  157. }
  158. delay(4000);
  159. }
  160.  
  161. //YES YES YES YES YES
  162. void gra_2(){
  163. }
  164.  
  165. //NO NO NO NO NO
  166. void gra_3(){
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement