Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_NeoPixel.h>
- #include <SoftwareSerial.h>
- #include <DFRobotDFPlayerMini.h>
- #define LED1 4
- #define LED2 5
- #define LED3 6
- #define LED4 7
- #define NUM_LIGHTS 60
- #define lightStripLen 2
- #define startPin A0
- #define outputPin 9
- int state = 0;
- //losowe kolory, moze ich byc wiecej, tylko trzeba to zmienic w kilku miejscach, jak cos to pisz
- int r1 [6] = {255, 255, 255, 0, 255, 255};
- int g1 [6] = {255, 0, 255, 255, 255, 0};
- int b1 [6] = {255, 0, 255, 0, 255, 255};
- int pozycje[4] = {0, 0, 0, 0};
- int kolory[4] = {0, 0, 0, 0};
- SoftwareSerial mySoftwareSerial(3, 2); // RX, TX
- DFRobotDFPlayerMini myDFPlayer;
- Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(NUM_LIGHTS, LED1, NEO_GRB + NEO_KHZ800);
- Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(NUM_LIGHTS, LED2, NEO_GRB + NEO_KHZ800);
- Adafruit_NeoPixel strip3 = Adafruit_NeoPixel(NUM_LIGHTS, LED3, NEO_GRB + NEO_KHZ800);
- Adafruit_NeoPixel strip4 = Adafruit_NeoPixel(NUM_LIGHTS, LED4, NEO_GRB + NEO_KHZ800);
- Adafruit_NeoPixel list[4] = {strip1, strip2, strip3, strip4};
- int num = 0;
- int32_t timeStart = 0;
- void setup()
- {
- mySoftwareSerial.begin(9600);
- Serial.begin(9600);
- if (!myDFPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3.
- Serial.println("podłączony dfplayer!");
- Serial.println(F("Unable to begin:"));
- Serial.println(F("1.Please recheck the connection!"));
- Serial.println(F("2.Please insert the SD card!"));
- while (true) {
- delay(0); // Code to compatible with ESP8266 watch dog.
- }
- }
- Serial.println(F("DFPlayer Mini online."));
- myDFPlayer.volume(30); //Set volume value. From 0 to 30
- strip1.begin();
- strip1.show(); // Initialize all pixels to 'off'
- strip2.begin();
- strip2.show(); // Initialize all pixels to 'off'
- strip3.begin();
- strip3.show(); // Initialize all pixels to 'off'
- strip4.begin();
- strip4.show(); // Initialize all pixels to 'off'
- pinMode(startPin, INPUT_PULLUP);
- pinMode(outputPin, OUTPUT);
- }
- //funkcja mowiaca jakie opoznienie ma byc w zaleznosci od tego ktory cykl/ ktory raz ma byc wlaczone odczekiwanie
- int getDelay(int num)
- {
- if (num < 300)
- return 500 / (num + 1) + 20; // to dla pierwszych 300 cykli - hiperbola malejaca z czasem -> coraz mniejsze opoznienie z czasem/cyklami
- else
- return 10; // pod koniec stale opoznienie 10ms -> pociag ma stala predkosc wiec stale opoznienie miedzy cyklami
- }
- void loop()
- {
- if (state == 1)
- {
- #define coile 180000
- if (millis() - timeStart > coile) //na 10 sekund
- {
- digitalWrite(outputPin, LOW);
- delay(10000);
- timeStart = millis();
- digitalWrite(outputPin, HIGH);
- num = 0;
- }
- else
- {
- for (int i = 0; i < 4; i++)
- {
- if (pozycje[i] == -1)
- {
- if (random(100) < 5) // TUTAJ DECYDUJESZ JAKI PROCENT SZANSY JEST NA ZAPALENIE PASKA !!!!!!!!!!
- {
- pozycje[i] = 0;
- kolory[i] = random(6);
- }
- }
- else
- {
- int len = 2; // tutaj decydujesz jak dlugi bedzie jeden przesuwajacy sie pasek (ilosc zapalonych na jednym stripie diod, ktore na raz moga byc zapalone)
- printNleds(&(list[i]), pozycje[i], len, kolory[i]);
- pozycje[i] += 1;
- if (pozycje[i] > NUM_LIGHTS)
- {
- pozycje[i] = -1;
- }
- }
- }
- delay(getDelay(num));
- Serial.println(getDelay(num));
- num++;
- }
- }
- if (digitalRead(startPin) == 1)
- {
- if (state == 0)
- timeStart = millis();
- state = 1;
- }
- else
- {
- state = 0;
- num = 0;
- }
- }
- void printNleds(Adafruit_NeoPixel* x, int start, int amount, int n)
- {
- for (int i = 0; i < NUM_LIGHTS; i++)
- x->setPixelColor(i, x->Color(0, 0, 0));
- for (int i = start; i < start + amount; i++)
- x->setPixelColor(i, x->Color(r1[n], g1[n], b1[n]));
- x->show();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement