Guest User

Untitled

a guest
Mar 2nd, 2015
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. //***************************************************************
  2. // DMX double pixels up
  3. // Once running, open the serial monitor to see what's happening.
  4. //***************************************************************
  5. #include "FastLED.h"
  6. #define LED_TYPE APA102
  7. #define DATA_PIN 4 // Update for your pin number
  8. #define CLOCK_PIN 5
  9. #define NUM_LEDS 12 // Update to number of pixels in your LED strip
  10. #define COLOR_ORDER RGB
  11. CRGB leds[NUM_LEDS];
  12.  
  13. // For DMX, the R,G,B for each pixel will be assigned a channel number, thus:
  14. uint16_t DMXchan = 3*NUM_LEDS; // Number of DMX channels.
  15. // Actually, the above would only need to be half of 3*NUM_LEDS since we are
  16. // doubling pixels up for this test, but I'm not worrying about that.
  17.  
  18. uint16_t pixel = 0; // for storing a pixel number
  19. uint16_t chanR = 0; // for storing the Red channel value
  20. uint16_t chanG = 0; // for storing the Green channel value
  21. uint16_t chanB = 0; // for storing the Blue channel value
  22.  
  23.  
  24. //---------------------------------------------------------------
  25. //---------------------------------------------------------------
  26. void setup(){
  27. delay(1000); // Power-up delay
  28. Serial.begin(57600); // Allows serial monitor output (check baud rate)
  29. FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  30. }
  31.  
  32.  
  33. //---------------------------------------------------------------
  34. void loop(){
  35. Serial.println("...........................................................");
  36. for (pixel = 0; pixel < NUM_LEDS; pixel++){
  37. if ((pixel & 0x01) == 0){ // Checks least significant bit to determine if even or odd
  38. // pixel number is an even
  39. Serial.print(" pixel "); Serial.print(pixel); Serial.print(" assigned: ");
  40. for (uint8_t c = 0; c < 3; c++){
  41. DMXchan = 3*((pixel+2)/2)-2+c;
  42. Serial.print(" chan="); Serial.print(DMXchan);
  43. }
  44. delay(50);
  45. } else {
  46. // pixel number is odd number
  47. Serial.print(" pixel "); Serial.print(pixel); Serial.print(" assigned: ");
  48. for (uint8_t c = 0; c < 3; c++){
  49. DMXchan = 3*((pixel+1)/2)-2+c;
  50. Serial.print(" chan="); Serial.print(DMXchan);
  51. }
  52. delay(50);
  53. Serial.println(" ");
  54. }
  55. Serial.println(" ");
  56. }
  57. delay(200);
  58.  
  59.  
  60. //================================================================
  61. // Read incoming serial DMX data.
  62. // Figure out pixel number based on incomming DMX channel number.
  63. //================================================================
  64.  
  65. Serial.println("******[SIMULATING RECEIVING CHANNELS, EACH WITH VALUE 255]******");
  66. int count = 0; // Using count to switch between R,G, and B LEDs in each pixel.
  67.  
  68. // Starting chan at 1, and adding +1 to DMXchan since DMX protocol has channels start at 1.
  69. for (uint16_t chan = 1; chan < DMXchan+1; chan++){
  70. pixel = ((chan+2)/3*2)-2; // Calculate what pixel the incoming channel belongs to.
  71.  
  72. Serial.print(" DMXChan "); Serial.print(chan);
  73. Serial.print(" goes to pixel "); Serial.print(pixel);
  74.  
  75. if (count == 0){
  76. Serial.print(" Adding R value, and duplicating to pixel "); Serial.print(pixel+1); Serial.println(" ");
  77. chanR = 255;
  78. chanG = 0;
  79. chanB = 0;
  80. }
  81. if (count == 1){
  82. Serial.print(" Adding G value, and duplicating to pixel "); Serial.print(pixel+1); Serial.println(" ");
  83. chanG = 255;
  84. }
  85. if (count == 2){
  86. Serial.print(" Adding B value, and duplicating to pixel "); Serial.print(pixel+1); Serial.println(" ");
  87. chanB = 255;
  88. }
  89. count++;
  90.  
  91. leds[pixel] = CRGB(chanR,chanG,chanB);
  92. FastLED.show();
  93. delay(200);
  94. leds[pixel+1] = CRGB(chanR,chanG,chanB); // Dublicate color to next pixel
  95. FastLED.show();
  96. delay(700);
  97.  
  98. if (count == 3){
  99. leds[pixel] = CRGB::Black;
  100. leds[pixel+1] = CRGB::Black;
  101. FastLED.show();
  102. }
  103. if (count > 2){count = 0;}
  104.  
  105. }
  106. delay(500);
  107. Serial.println(" ");
  108.  
  109.  
  110. } // ----End main loop----
Advertisement
Add Comment
Please, Sign In to add comment