Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.01 KB | None | 0 0
  1. #include <Adafruit_NeoPixel.h>
  2. #include <SoftwareSerial.h>
  3.  
  4. #include <DFRobotDFPlayerMini.h>
  5.  
  6. #define LED1 4
  7. #define LED2 5
  8. #define LED3 6
  9. #define LED4 7
  10. #define NUM_LIGHTS 60
  11. #define lightStripLen 2
  12.  
  13.  
  14. #define startPin A0
  15.  
  16.  
  17. #define outputPin 9
  18.  
  19. int state = 0;
  20.  
  21. //losowe kolory, moze ich byc wiecej, tylko trzeba to zmienic w kilku miejscach, jak cos to pisz
  22. int r1 [6] = {255, 255, 255, 0, 255, 255};
  23. int g1 [6] = {255, 0, 255, 255, 255, 0};
  24. int b1 [6] = {255, 0, 255, 0, 255, 255};
  25.  
  26. int pozycje[4] = {0, 0, 0, 0};
  27. int kolory[4] = {0, 0, 0, 0};
  28.  
  29.  
  30. SoftwareSerial mySoftwareSerial(3, 2); // RX, TX
  31. DFRobotDFPlayerMini myDFPlayer;
  32.  
  33. Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(NUM_LIGHTS, LED1, NEO_GRB + NEO_KHZ800);
  34. Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(NUM_LIGHTS, LED2, NEO_GRB + NEO_KHZ800);
  35. Adafruit_NeoPixel strip3 = Adafruit_NeoPixel(NUM_LIGHTS, LED3, NEO_GRB + NEO_KHZ800);
  36. Adafruit_NeoPixel strip4 = Adafruit_NeoPixel(NUM_LIGHTS, LED4, NEO_GRB + NEO_KHZ800);
  37.  
  38. Adafruit_NeoPixel list[4] = {strip1, strip2, strip3, strip4};
  39.  
  40. int num = 0;
  41. int32_t timeStart = 0;
  42. void setup()
  43. {
  44. mySoftwareSerial.begin(9600);
  45. Serial.begin(9600);
  46.  
  47. if (!myDFPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3.
  48. Serial.println("podłączony dfplayer!");
  49. Serial.println(F("Unable to begin:"));
  50. Serial.println(F("1.Please recheck the connection!"));
  51. Serial.println(F("2.Please insert the SD card!"));
  52. while (true) {
  53. delay(0); // Code to compatible with ESP8266 watch dog.
  54. }
  55. }
  56. Serial.println(F("DFPlayer Mini online."));
  57.  
  58. myDFPlayer.volume(30); //Set volume value. From 0 to 30
  59.  
  60.  
  61. strip1.begin();
  62. strip1.show(); // Initialize all pixels to 'off'
  63. strip2.begin();
  64. strip2.show(); // Initialize all pixels to 'off'
  65. strip3.begin();
  66. strip3.show(); // Initialize all pixels to 'off'
  67. strip4.begin();
  68. strip4.show(); // Initialize all pixels to 'off'
  69.  
  70.  
  71. pinMode(startPin, INPUT_PULLUP);
  72. pinMode(outputPin, OUTPUT);
  73. }
  74.  
  75. //funkcja mowiaca jakie opoznienie ma byc w zaleznosci od tego ktory cykl/ ktory raz ma byc wlaczone odczekiwanie
  76. int getDelay(int num)
  77. {
  78. if (num < 300)
  79. return 500 / (num + 1) + 20; // to dla pierwszych 300 cykli - hiperbola malejaca z czasem -> coraz mniejsze opoznienie z czasem/cyklami
  80. else
  81. return 10; // pod koniec stale opoznienie 10ms -> pociag ma stala predkosc wiec stale opoznienie miedzy cyklami
  82. }
  83.  
  84. void loop()
  85. {
  86. if (state == 1)
  87. {
  88. #define coile 180000
  89. if (millis() - timeStart > coile) //na 10 sekund
  90. {
  91. digitalWrite(outputPin, LOW);
  92. delay(10000);
  93. timeStart = millis();
  94. digitalWrite(outputPin, HIGH);
  95. num = 0;
  96.  
  97. }
  98. else
  99. {
  100.  
  101. for (int i = 0; i < 4; i++)
  102. {
  103. if (pozycje[i] == -1)
  104. {
  105. if (random(100) < 5) // TUTAJ DECYDUJESZ JAKI PROCENT SZANSY JEST NA ZAPALENIE PASKA !!!!!!!!!!
  106. {
  107. pozycje[i] = 0;
  108. kolory[i] = random(6);
  109. }
  110. }
  111. else
  112. {
  113. int len = 2; // tutaj decydujesz jak dlugi bedzie jeden przesuwajacy sie pasek (ilosc zapalonych na jednym stripie diod, ktore na raz moga byc zapalone)
  114. printNleds(&(list[i]), pozycje[i], len, kolory[i]);
  115. pozycje[i] += 1;
  116. if (pozycje[i] > NUM_LIGHTS)
  117. {
  118. pozycje[i] = -1;
  119. }
  120. }
  121. }
  122.  
  123. delay(getDelay(num));
  124. Serial.println(getDelay(num));
  125. num++;
  126. }
  127. }
  128.  
  129. if (digitalRead(startPin) == 1)
  130. {
  131. if (state == 0)
  132. timeStart = millis();
  133.  
  134. state = 1;
  135. }
  136. else
  137. {
  138. state = 0;
  139. num = 0;
  140. }
  141. }
  142.  
  143.  
  144.  
  145. void printNleds(Adafruit_NeoPixel* x, int start, int amount, int n)
  146. {
  147. for (int i = 0; i < NUM_LIGHTS; i++)
  148. x->setPixelColor(i, x->Color(0, 0, 0));
  149.  
  150. for (int i = start; i < start + amount; i++)
  151. x->setPixelColor(i, x->Color(r1[n], g1[n], b1[n]));
  152.  
  153. x->show();
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement