Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <DMXSerial.h>
- #define Console Serial
- char Mode_const = '0';
- long start = 0;
- long ende = 0;
- bool rightadress = false;
- void setup() {
- Serial.begin(9600);
- Serial.setTimeout(100);
- while (! Serial);
- Console.println("pls enter Mode: r for Recieve; s for Send; b for break");
- //DMXSerial.resetUpdated();
- }
- static constexpr const uint16_t channels = 512;
- static constexpr const uint16_t channels_per_line = 32;
- static constexpr const uint16_t channels_per_group = 8;
- void printByte(uint8_t b) {
- }
- void loop() {
- while (! Serial);
- char Mode = Serial.read();
- if (Mode == 'r' || Mode =='R') {
- //Setup for recieving
- rightadress = false;
- Serial.println("rec");
- DMXSerial.init(DMXReceiver);
- Mode_const = '1';
- }
- if (Mode == 's' || Mode == 'S') {
- //Setup for sending
- DMXSerial.init(DMXController);
- Mode_const = '2';
- }
- if (Mode == 'b' || Mode == 'B') {
- //to stop everything
- rightadress = false;
- Mode_const = '0';
- Console.println("stopping...");
- }
- if (Mode_const == '1'){
- //actual recieving
- if (DMXSerial.dataUpdated()) {
- DMXSerial.resetUpdated();
- // For the dumb consoles (like the Arduino IDE serial console), add
- // some newlines to separate subsequent dumps
- Console.println();
- Console.println();
- for (uint16_t i = 0; i < channels; ++i) {
- // Channels are 1-based
- uint16_t channel = i + 1;
- if (i % channels_per_line == 0) {
- Console.println();
- // Prefix each line with the DMX channel number, adding spaces to align
- if (channel < 100) Console.write(' ');
- if (channel < 10) Console.write(' ');
- Console.print(channel);
- Console.print(F(": "));
- } else {
- // Print one space between channels, and two spaces between each group
- if (i % channels_per_group == 0)
- Console.write(' ');
- Console.write(' ');
- }
- // Print the actual channel value, padding with a zero if needed
- uint8_t value = DMXSerial.read(channel);
- if (value < 0x10) Console.write('0');
- Console.print(value, HEX);
- }
- }
- else {
- Serial.println("");
- Serial.println("no DMX");
- delay(500);
- }
- }
- if (Mode_const == '2'){
- //actual sending
- while(rightadress == false) {
- Serial.read();
- Serial.println("test1");
- while(!Serial) {};
- Serial.println("start:");
- while(!Serial.available()){}
- start = Serial.parseInt();
- while(!Serial) {};
- Serial.read();
- Serial.println("ende::");
- while(!Serial.available()){}
- ende = Serial.parseInt();
- Serial.println(start);
- Serial.println("");
- Serial.println(ende);
- if (start <= 512 && start > 0 && ende <= 512 && ende > 0){
- while(!Serial) {};
- rightadress = true;
- Serial.println("test2");
- }
- else {
- Serial.println("one (or more) adresses weren't possible");
- while(!Serial) {};
- }
- }
- for (int i = start; i <= ende; i++) {
- DMXSerial.write(i, 255);
- Serial.println("test3");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement