MR_Rednax

dmx code

Jun 1st, 2022 (edited)
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SerialMP3Player.h>
  2. #include <Wire.h>
  3. #include <Adafruit_PWMServoDriver.h>
  4. #include <DmxSimple.h>
  5.  
  6.   #define work_light_indicator 12
  7.   #define dmx_pin 3
  8.   #define ARDUINO_RX 10
  9.   #define ARDUINO_TX 11
  10.   #define flash_delay 40
  11.   #define textInterval 3000
  12.   #define SERVOMIN 100
  13.   #define SERVOMAX 600
  14.   #define servoFreq 60   //this command is in HZ
  15.  
  16.   Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
  17.   SerialMP3Player mp3(ARDUINO_RX,ARDUINO_TX);
  18.  
  19.   int textprint                   = 0  ;
  20.   int flash                       = 0  ;
  21.   int randomflash                 = 8  ;
  22.   int randomdelay                 = 500;
  23.   int randomintensity             = 255;
  24.   int randomprogram               = 0  ;
  25.   int Run                         = 0  ;
  26.   int Run_sene                    = 0  ;
  27.   int flashOn                     = 0  ;
  28.   int sensor_1                    = 0  ;
  29.   int value_1                     = 0  ;
  30.   int steps                       = 0  ;
  31.   int work_light                  = 0  ;
  32.   int sound_on                    = 0  ;
  33.   unsigned long previousMillis    = 0  ;
  34.   unsigned long textMillis        = 0  ;
  35.   unsigned long sene_Millis       = 0  ;
  36.   unsigned long work_light_millis = 0  ;
  37.  
  38.  
  39.  
  40. void setup() {
  41.   Serial.begin(15000);
  42.   pinMode(work_light_indicator, OUTPUT);
  43.   mp3.begin(15000);
  44.   mp3.sendCommand(CMD_SEL_DEV, 0, 2);
  45.  
  46.   DmxSimple.usePin(dmx_pin);
  47.   DmxSimple.write(6,255);
  48.   DmxSimple.write(12,255);       // (dmx channel, brightness)
  49.  
  50.   pwm.begin();
  51.   pwm.setPWMFreq(servoFreq);
  52.  
  53.  
  54.   delay(2000);
  55. }
  56.  
  57.  
  58. void DmX(){
  59.   unsigned long currentMillis  = millis();
  60.  
  61.  
  62.  
  63. //#========================================================================= flash =========================================================================#
  64.   if(currentMillis - previousMillis >= randomdelay && Run_sene == 0 && work_light == 0){
  65.     previousMillis = currentMillis;
  66.     Run = 1;
  67.     randomdelay = random(2500, 15000);
  68.     mp3.play(random(1,4));
  69.   }
  70.   if(Run == 1 && flash <= randomflash && flashOn == 0 && currentMillis - previousMillis >= flash_delay){
  71.       previousMillis = currentMillis;
  72.       for(int i = 1; i <= 11; ++i) {
  73.          if (i < 6) {//for the channels 1 to 5
  74.            DmxSimple.write(i, randomintensity);
  75.          }
  76.          if (i < 12 and i > 6) {//for the channels 7 to 11
  77.            DmxSimple.write(i, 0);
  78.          }}
  79.       flashOn = 1;
  80.   }
  81.   if(currentMillis - previousMillis >= flash_delay && flashOn == 1){
  82.       previousMillis = currentMillis;
  83.       for(int i = 1; i <= 11; ++i) {
  84.          if (i < 6) {//for the channels 1 to 5
  85.            DmxSimple.write(i, 0);
  86.          }
  87.          if (i < 12 and i > 6) {//for the channels 7 to 11
  88.            DmxSimple.write(i, randomintensity);
  89.          }}
  90.       randomintensity = random(20, 255);
  91.       flash = flash + 1;
  92.       flashOn = 0;
  93.    }
  94.    if(Run == 1 && flash == randomflash){
  95.       flash = 0;
  96.       sound_on = 0;
  97.       for(int i = 1; i <= 11; ++i) {
  98.          if (i < 6) {//for the channels 1 to 5
  99.            DmxSimple.write(i, 0);
  100.          }
  101.          if (i < 12 and i > 6) {//for the channels 7 to 11
  102.            DmxSimple.write(i, 0);
  103.          }}
  104.       Run = 0;
  105.       randomflash = random(8,16);
  106.   }
  107.  
  108. //#====================================================================== work  light ======================================================================#
  109.   if(work_light == 1){
  110.     for(int i = 1; i <= 100; ++i) {
  111.          if (i < 100) {//for all channels
  112.            DmxSimple.write(i, 255);
  113.          }
  114.     }
  115.   }
  116.   if(work_light == 0 && analogRead(A1) >= 500){
  117.     for(int i = 1; i <= 100; ++i) {
  118.          if (i < 100) {//for all channels
  119.            DmxSimple.write(i, 0);
  120.          }    
  121.     }
  122.     DmxSimple.write(6, 255);
  123.     DmxSimple.write(12, 255);
  124.   }
  125.  
  126. //#====================================================================== sene  flash ======================================================================#
  127. if(Run_sene >= 1 && flash <= 50 && flashOn == 0 && currentMillis - previousMillis >= flash_delay){
  128.       previousMillis = currentMillis;
  129.       DmxSimple.write(1, randomintensity);
  130.       randomintensity = random(20, 255);
  131.       flashOn = 1;
  132.   }
  133.   if(currentMillis - previousMillis >= flash_delay && flashOn == 1){
  134.       previousMillis = currentMillis;
  135.       DmxSimple.write(1, randomintensity);
  136.       randomintensity = random(20, 255);
  137.       flash = flash + 1;
  138.       flashOn = 0;
  139.    }
  140.    if(Run_sene >= 1 && flash == 50){
  141.       flash = 0;
  142.       Run_sene = 0;
  143.       for(int i = 1; i <= 11; ++i) {
  144.          if (i < 6) {//for the channels 1 to 5
  145.            DmxSimple.write(i, 0);
  146.          }
  147.       }
  148.    }
  149. }
  150.  
  151.  
  152.  
  153.  
  154. void loop(){
  155.   unsigned long currentMillis  = millis();
  156.   DmX();
  157.   sensoren();
  158.  
  159. //#============================================================================================#
  160. //#                                           print text                                       #
  161. //#============================================================================================#
  162.   if(currentMillis - textMillis >= textInterval){
  163.     textMillis = currentMillis;
  164.     text();
  165.     textprint = textprint + 1;
  166.   }
  167.  
  168.  
  169.  
  170. //#========================================== sene 1 ==========================================#
  171.   if(Run_sene == 1 && steps == 0 && currentMillis - sene_Millis >= 50){
  172.     steps = 1;
  173.     sene_Millis = currentMillis;
  174.     DmxSimple.write(1, 255);
  175.   }
  176.  
  177.  
  178. //#========================================== sene 2 ==========================================#
  179.   if(Run_sene == 2 && steps == 0){
  180.    
  181.   }
  182.  
  183.  
  184. //#========================================== sene 3 ==========================================#
  185.   if(Run_sene == 3 && steps == 0){
  186.    
  187.   }
  188. }
Add Comment
Please, Sign In to add comment