Advertisement
benedict_naebers

Arduino DMXTestbox Code

Aug 27th, 2020 (edited)
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.34 KB | None | 0 0
  1. #include <DMXSerial.h>
  2. #define Console Serial
  3. char Mode_const = '0';
  4. long start = 0;
  5. long ende = 0;
  6. bool rightadress = false;
  7.  
  8. void setup() {
  9.  
  10.   Serial.begin(9600);
  11.   Serial.setTimeout(100);
  12.   while (! Serial);
  13.   Console.println("pls enter Mode: r for Recieve; s for Send; b for break");
  14.   //DMXSerial.resetUpdated();
  15. }
  16.  
  17. static constexpr const uint16_t channels = 512;
  18. static constexpr const uint16_t channels_per_line = 32;
  19. static constexpr const uint16_t channels_per_group = 8;
  20.  
  21. void printByte(uint8_t b) {
  22. }
  23.  
  24. void loop() {
  25.     while (! Serial);
  26.     char Mode = Serial.read();    
  27.  
  28.     if (Mode == 'r' || Mode =='R') {
  29.       //Setup for recieving
  30.       rightadress = false;
  31.       Serial.println("rec");
  32.       DMXSerial.init(DMXReceiver);
  33.       Mode_const = '1';
  34.     }
  35.  
  36.     if (Mode == 's' || Mode == 'S') {
  37.       //Setup for sending
  38.       DMXSerial.init(DMXController);
  39.       Mode_const = '2';
  40.  
  41.     }
  42.     if (Mode == 'b' || Mode == 'B') {
  43.       //to stop everything
  44.       rightadress = false;
  45.       Mode_const = '0';
  46.       Console.println("stopping...");
  47.     }
  48.    
  49.     if (Mode_const == '1'){
  50.       //actual recieving
  51.       if (DMXSerial.dataUpdated()) {
  52.       DMXSerial.resetUpdated();
  53.       // For the dumb consoles (like the Arduino IDE serial console), add
  54.       // some newlines to separate subsequent dumps
  55.       Console.println();
  56.       Console.println();
  57.  
  58.       for (uint16_t i = 0; i < channels; ++i) {
  59.         // Channels are 1-based
  60.         uint16_t channel = i + 1;
  61.  
  62.         if (i % channels_per_line == 0) {
  63.           Console.println();
  64.           // Prefix each line with the DMX channel number, adding spaces to align
  65.        if (channel < 100) Console.write(' ');
  66.        if (channel < 10) Console.write(' ');
  67.        Console.print(channel);
  68.        Console.print(F(": "));
  69.         } else {
  70.           // Print one space between channels, and two spaces between each group
  71.           if (i % channels_per_group == 0)
  72.           Console.write(' ');
  73.         Console.write(' ');
  74.       }
  75.  
  76.       // Print the actual channel value, padding with a zero if needed
  77.       uint8_t value = DMXSerial.read(channel);
  78.       if (value < 0x10) Console.write('0');
  79.       Console.print(value, HEX);
  80.     }
  81.     }
  82.     else {
  83.       Serial.println("");
  84.       Serial.println("no DMX");
  85.       delay(500);
  86.   }
  87.      
  88.     }
  89.    
  90.     if (Mode_const == '2'){
  91.       //actual sending
  92.  
  93.       while(rightadress == false) {
  94.         Serial.read();
  95.         Serial.println("test1");
  96.         while(!Serial) {};
  97.         Serial.println("start:");
  98.         while(!Serial.available()){}
  99.         start = Serial.parseInt();
  100.         while(!Serial) {};
  101.                 Serial.read();
  102.  
  103.         Serial.println("ende::");
  104.         while(!Serial.available()){}
  105.         ende = Serial.parseInt();
  106.         Serial.println(start);
  107.         Serial.println("");
  108.         Serial.println(ende);
  109.         if (start <= 512 && start > 0 && ende <= 512 && ende > 0){
  110.           while(!Serial) {};
  111.           rightadress = true;
  112.           Serial.println("test2");
  113.  
  114.         }
  115.         else {
  116.           Serial.println("one (or more) adresses weren't possible");
  117.           while(!Serial) {};
  118.  
  119.         }
  120.  
  121.       }
  122.         for (int i = start; i <= ende; i++) {
  123.           DMXSerial.write(i, 255);
  124.           Serial.println("test3");
  125.       }
  126.  
  127.      
  128.     }
  129.    
  130. }
  131.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement