Facebook
From Anorexic Pig, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 108
  1. const byte koniecczasu = 4;
  2. const byte wygrana = 5;
  3. const byte pilot = 6;
  4. bool a = 0;
  5. bool b = 0;
  6. bool c = 0;
  7. // biblioteki do dzwięku //
  8. #include "SoftwareSerial.h"
  9. #include "DFRobotDFPlayerMini.h"
  10.  
  11.  
  12. SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
  13. DFRobotDFPlayerMini myDFPlayer;
  14.  
  15. void setup() {
  16. //  put your setup code here, to run once:
  17.   mySoftwareSerial.begin(9600);
  18.   Serial.begin(115200);
  19.  
  20.      if (!myDFPlayer.begin(mySoftwareSerial)) {  //Use softwareSerial to communicate with mp3.
  21.     Serial.println(F("Unable to begin:"));
  22.     Serial.println(F("1.Please recheck the connection!"));
  23.     Serial.println(F("2.Please insert the SD card!"));
  24.     while(true);
  25.   }
  26.  
  27.  
  28.   pinMode(koniecczasu, INPUT_PULLUP);
  29.   pinMode(wygrana, INPUT_PULLUP);
  30.   pinMode(pilot, INPUT_PULLUP);
  31.   myDFPlayer.setTimeOut(200);
  32.  
  33. myDFPlayer.play(2);
  34.  
  35. }
  36. /*      utwory
  37.  *  000 - wstep
  38.  *  001 - niepowodzenie
  39.  *  002 - muzyka
  40.  *  003 - wygrana
  41.  *  
  42.  *  1- przegrana
  43.  *  2- uratowanie
  44.  *  3- wstep
  45.  *  4- podkład
  46.  *  
  47.  *  
  48.  */
  49. void loop() {
  50.  
  51. if ((digitalRead(pilot) == HIGH) && (c == 0)){
  52.   c = 1;
  53.  Serial.println("c - wstep");
  54.  myDFPlayer.volume(21);
  55.  delay(1000);
  56.  myDFPlayer.play(3);// 000 wstęp do gry
  57.  delay(61000);
  58.  Serial.println("koniec wstepu");
  59.  myDFPlayer.volume(18);
  60.  delay(300);
  61.  myDFPlayer.play(4);
  62.  
  63. }
  64.  
  65. if ((digitalRead(koniecczasu) == LOW) && (a==0)){
  66.   a=1;
  67.   Serial.println("a - koniec czasu");
  68.   myDFPlayer.volume(21);
  69.   delay(300);
  70.   myDFPlayer.play(1); //001 koniec czasu
  71.   delay(34000);
  72.   myDFPlayer.volume(18);
  73.   delay(300);
  74.   myDFPlayer.play(4);
  75.    Serial.println("koniec ifa koniec czasu");
  76. }
  77.  
  78. if ((digitalRead(wygrana) == LOW) && (b==0)){
  79.   b=1;
  80.   Serial.println("b - wygrana");
  81.   myDFPlayer.volume(21);
  82.   delay(300);
  83.   myDFPlayer.play(2); //003 wygrana
  84.    Serial.println("koniec ifa wygrana ");
  85. }
  86. delay(500);
  87. Serial.println("kolo");
  88. Serial.println("koniecczasu: ");
  89. Serial.print(digitalRead(koniecczasu));
  90. Serial.println("wygrana: ");
  91. Serial.print(digitalRead(wygrana));
  92. Serial.println("koniecczasu: ");
  93. Serial.print(digitalRead(pilot));
  94. }