v12345vtm

dmxarduino

Apr 2nd, 2018
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. // - - - - -
  2. // DmxSerial - A hardware supported interface to DMX.
  3. // DMXSerialFlow.ino: Sample DMX application for sending 60 DMX values.
  4. // Copyright (c) 2014-2015 by Matthias Hertel, http://www.mathertel.de
  5. // This work is licensed under a BSD style license. See http://www.mathertel.de/License.aspx
  6. //
  7. // Documentation and samples are available at http://www.mathertel.de/Arduino
  8. // 25.07.2011 creation of the DmxSerial library.
  9. // 01.07.2013 published version of the example applikation
  10. //
  11. // This is an example of how to send a more complex RGB based pattern of colors
  12. // over a DMX line.
  13. // The values for one of the channels can be watched at the PWM outputs of the Arduino Board.
  14. // - - - - -
  15.  
  16. #include <DMXSerial.h>
  17.  
  18. // Constants for demo program
  19.  
  20. const int RedPin = 9; // PWM output pin for Red Light.
  21. const int GreenPin = 6; // PWM output pin for Green Light.
  22. const int BluePin = 5; // PWM output pin for Blue Light.
  23.  
  24. #define PIXELS 60
  25.  
  26. void setup(void)
  27. {
  28. // Serial.begin(57600); // only on Leonardo
  29. // Serial.println("DMXSerialFlow DMX Example");
  30.  
  31. DMXSerial.init(DMXController);
  32.  
  33. // Set the number of channels the controller will send
  34. // this call is not needed, because the DMXController extends the DMX packet length automatically when data is added.
  35. // DMXSerial.maxChannel(60);
  36.  
  37. pinMode(RedPin, OUTPUT); // sets the digital pin as output
  38. pinMode(GreenPin, OUTPUT);
  39. pinMode(BluePin, OUTPUT);
  40.  
  41. analogWrite(RedPin, 80);
  42. analogWrite(GreenPin, 80);
  43. analogWrite(BluePin, 80);
  44. } // setup
  45.  
  46.  
  47. // set 3 channels to a RGB value with the specified hue (0...764)
  48. void setChannelRGB(int channel, int hue) {
  49. hue = hue % 765;
  50. if (hue < 256) {
  51. /// blue to red
  52. DMXSerial.write(channel , hue);
  53. DMXSerial.write(channel+1, 0);
  54. DMXSerial.write(channel+2, 255-hue);
  55.  
  56. } else if (hue < 511) {
  57. /// red to green
  58. DMXSerial.write(channel , 255 - (hue-255));
  59. DMXSerial.write(channel+1, hue-255);
  60. DMXSerial.write(channel+2, 0);
  61.  
  62. } else {
  63. /// green to blue
  64. DMXSerial.write(channel , 0);
  65. DMXSerial.write(channel+1, 255 - (hue-510));
  66. DMXSerial.write(channel+2, hue-510);
  67. } // if
  68. } // setChannelRGB()
  69.  
  70.  
  71. void loop(void)
  72. {
  73. unsigned long now = millis();
  74. int testchannel = 1;
  75.  
  76.  
  77. DMXSerial.write(8 , 255); //r
  78. DMXSerial.write(9 , 0); //g
  79. DMXSerial.write(10 , 0); //b
  80.  
  81. DMXSerial.write(1 , 20); //r
  82. DMXSerial.write(2 , 0); //g
  83. DMXSerial.write(3 , 0); //b
  84.  
  85.  
  86. analogWrite(9, 255);
  87. analogWrite(5, 0);
  88. analogWrite(6, 0);
  89.  
  90.  
  91.  
  92. delay (300);
  93. DMXSerial.write(1 , 0); //r
  94. DMXSerial.write(2 , 20); //g
  95. DMXSerial.write(3 , 0); //b
  96.  
  97.  
  98. analogWrite(9, 0);
  99. analogWrite(5, 255);
  100. analogWrite(6, 0);
  101. delay (300);
  102.  
  103. DMXSerial.write(1 , 0); //r
  104. DMXSerial.write(2 , 0); //g
  105. DMXSerial.write(3 , 20); //b
  106.  
  107.  
  108. analogWrite(9, 0);
  109. analogWrite(5, 0);
  110. analogWrite(6, 255);
  111.  
  112.  
  113.  
  114.  
  115. DMXSerial.write(8 , 0); //r
  116. DMXSerial.write(9 , 0); //g
  117. DMXSerial.write(10 , 0); //b
  118.  
  119.  
  120.  
  121. delay (5000);
  122.  
  123. // create some DMX test values: 5 RGB channels
  124. // adjust the "12" for changing the speed
  125. // int alpha = (now / 12) % 765;
  126.  
  127. // uncomment this line to have a scenario where DMX values are changed ~ 2 times the second
  128. // alpha = (alpha / 64) * 64;
  129. // uncomment this line to have a scenario where DMX values are changed every 5 seconds
  130. // alpha &= 0xFF00;
  131.  
  132. // for (int n = 0; n < PIXELS; n++) {
  133. // setChannelRGB (n*3+1, alpha + n*64);
  134. // } // for
  135.  
  136. // send the DMX values fo the testchannel to the PWM pins
  137. // analogWrite(RedPin, DMXSerial.read(testchannel+0));
  138. // analogWrite(GreenPin, DMXSerial.read(testchannel+1));
  139. // analogWrite(BluePin, DMXSerial.read(testchannel+2));
  140.  
  141.  
  142.  
  143. }
  144.  
  145. // End
Advertisement
Add Comment
Please, Sign In to add comment