Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SerialMP3Player.h>
- #include <Wire.h>
- #include <Adafruit_PWMServoDriver.h>
- #include <DmxSimple.h>
- #define work_light_indicator 12
- #define dmx_pin 3
- #define ARDUINO_RX 10
- #define ARDUINO_TX 11
- #define flash_delay 40
- #define textInterval 3000
- #define SERVOMIN 100
- #define SERVOMAX 600
- #define servoFreq 60 //this command is in HZ
- Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
- SerialMP3Player mp3(ARDUINO_RX,ARDUINO_TX);
- int textprint = 0 ;
- int flash = 0 ;
- int randomflash = 8 ;
- int randomdelay = 500;
- int randomintensity = 255;
- int randomprogram = 0 ;
- int Run = 0 ;
- int Run_sene = 0 ;
- int flashOn = 0 ;
- int sensor_1 = 0 ;
- int value_1 = 0 ;
- int steps = 0 ;
- int work_light = 0 ;
- int sound_on = 0 ;
- unsigned long previousMillis = 0 ;
- unsigned long textMillis = 0 ;
- unsigned long sene_Millis = 0 ;
- unsigned long work_light_millis = 0 ;
- void setup() {
- Serial.begin(15000);
- pinMode(work_light_indicator, OUTPUT);
- mp3.begin(15000);
- mp3.sendCommand(CMD_SEL_DEV, 0, 2);
- DmxSimple.usePin(dmx_pin);
- DmxSimple.write(6,255);
- DmxSimple.write(12,255); // (dmx channel, brightness)
- pwm.begin();
- pwm.setPWMFreq(servoFreq);
- delay(2000);
- }
- void DmX(){
- unsigned long currentMillis = millis();
- //#========================================================================= flash =========================================================================#
- if(currentMillis - previousMillis >= randomdelay && Run_sene == 0 && work_light == 0){
- previousMillis = currentMillis;
- Run = 1;
- randomdelay = random(2500, 15000);
- mp3.play(random(1,4));
- }
- if(Run == 1 && flash <= randomflash && flashOn == 0 && currentMillis - previousMillis >= flash_delay){
- previousMillis = currentMillis;
- for(int i = 1; i <= 11; ++i) {
- if (i < 6) {//for the channels 1 to 5
- DmxSimple.write(i, randomintensity);
- }
- if (i < 12 and i > 6) {//for the channels 7 to 11
- DmxSimple.write(i, 0);
- }}
- flashOn = 1;
- }
- if(currentMillis - previousMillis >= flash_delay && flashOn == 1){
- previousMillis = currentMillis;
- for(int i = 1; i <= 11; ++i) {
- if (i < 6) {//for the channels 1 to 5
- DmxSimple.write(i, 0);
- }
- if (i < 12 and i > 6) {//for the channels 7 to 11
- DmxSimple.write(i, randomintensity);
- }}
- randomintensity = random(20, 255);
- flash = flash + 1;
- flashOn = 0;
- }
- if(Run == 1 && flash == randomflash){
- flash = 0;
- sound_on = 0;
- for(int i = 1; i <= 11; ++i) {
- if (i < 6) {//for the channels 1 to 5
- DmxSimple.write(i, 0);
- }
- if (i < 12 and i > 6) {//for the channels 7 to 11
- DmxSimple.write(i, 0);
- }}
- Run = 0;
- randomflash = random(8,16);
- }
- //#====================================================================== work light ======================================================================#
- if(work_light == 1){
- for(int i = 1; i <= 100; ++i) {
- if (i < 100) {//for all channels
- DmxSimple.write(i, 255);
- }
- }
- }
- if(work_light == 0 && analogRead(A1) >= 500){
- for(int i = 1; i <= 100; ++i) {
- if (i < 100) {//for all channels
- DmxSimple.write(i, 0);
- }
- }
- DmxSimple.write(6, 255);
- DmxSimple.write(12, 255);
- }
- //#====================================================================== sene flash ======================================================================#
- if(Run_sene >= 1 && flash <= 50 && flashOn == 0 && currentMillis - previousMillis >= flash_delay){
- previousMillis = currentMillis;
- DmxSimple.write(1, randomintensity);
- randomintensity = random(20, 255);
- flashOn = 1;
- }
- if(currentMillis - previousMillis >= flash_delay && flashOn == 1){
- previousMillis = currentMillis;
- DmxSimple.write(1, randomintensity);
- randomintensity = random(20, 255);
- flash = flash + 1;
- flashOn = 0;
- }
- if(Run_sene >= 1 && flash == 50){
- flash = 0;
- Run_sene = 0;
- for(int i = 1; i <= 11; ++i) {
- if (i < 6) {//for the channels 1 to 5
- DmxSimple.write(i, 0);
- }
- }
- }
- }
- void loop(){
- unsigned long currentMillis = millis();
- DmX();
- sensoren();
- //#============================================================================================#
- //# print text #
- //#============================================================================================#
- if(currentMillis - textMillis >= textInterval){
- textMillis = currentMillis;
- text();
- textprint = textprint + 1;
- }
- //#========================================== sene 1 ==========================================#
- if(Run_sene == 1 && steps == 0 && currentMillis - sene_Millis >= 50){
- steps = 1;
- sene_Millis = currentMillis;
- DmxSimple.write(1, 255);
- }
- //#========================================== sene 2 ==========================================#
- if(Run_sene == 2 && steps == 0){
- }
- //#========================================== sene 3 ==========================================#
- if(Run_sene == 3 && steps == 0){
- }
- }
Add Comment
Please, Sign In to add comment