Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Removing Random from Victors sketch

  1. #1
    Join Date
    Jan 2019
    Posts
    82
    Post Thanks / Like

    Default Removing Random from Victors sketch

    because I am using both pixel controller and arduino if I lose my computer the pixel controller doesn't turn on anything and I would like to do same with arduino? What would be the easiest way to shut that off that still gives a valid code the arduino will take

  2. #2
    Join Date
    Oct 2019
    Location
    SoCal
    Posts
    59
    Post Thanks / Like

    Default Re: Removing Random from Victors sketch

    Quote Originally Posted by mojuave1 View Post
    because I am using both pixel controller and arduino if I lose my computer the pixel controller doesn't turn on anything and I would like to do same with arduino? What would be the easiest way to shut that off that still gives a valid code the arduino will take
    why not just comment out the section for the random sequence?

  3. #3
    Join Date
    Jan 2019
    Posts
    82
    Post Thanks / Like

    Default Re: Removing Random from Victors sketch

    Quote Originally Posted by LateraLiz View Post
    why not just comment out the section for the random sequence?
    It doesn't work I commented out that , the time out , sequence watch dogand a few others but nothing worked. The only code IDE accepted was removal of TIME OUT, random and sequence loop but my lights still come on

  4. #4
    Join Date
    Jan 2019
    Posts
    82
    Post Thanks / Like

    Default Re: Removing Random from Victors sketch

    I don't know really anything about arduino programming and what needs to be left and what can be removed

  5. #5
    Join Date
    Jan 2016
    Location
    Moline, IL
    Posts
    105
    Post Thanks / Like

    Default Re: Removing Random from Victors sketch

    I commented out what *should* be the random code. I copied it from the original post and just commented out the random code section.
    Code:
    // This code was written by Victor Perez for doityourselfchristmas.com based on the code from Zparticle, Si_champion and Neil Tapp.
     // To adapt the code to your case, just change this top section, with the #define lines.
     
     // Includes the watchdog timer library
     #include <avr/wdt.h>
     
     // This sets how many channels will vixen be sending. Can be set to any number from 1 to 48 for Arduino Mega, and 1 to 18 for Arduino Uno.
     #define CHANNEL_COUNT 16
    
     // speed for the com port for talking with vixen. From 9600 to 115200. Use the same speed as set in Vixen.
     #define VIXEN_COM_SPEED 57600
     
     // Timeout waiting for serial input before going to random mode (in milliseconds).
     #define TIME_OUT 1000
     
     // If the relays turn On and Off opposite to Vixen sequence, change "#define MODE NOT_INVERTED" for "#define MODE INVERTED"
     #define NOT_INVERTED 0
     #define INVERTED 1
     #define MODE NOT_INVERTED
    
     // which pins control which channels
     // You can change these assignment to use different pins, but be very careful to not repeat the same pin number for 2 channels. 
     // DO NOT use pings 0 and 1, as those are for the serial port to talk to the computer.
     #define CH01 2
     #define CH02 3
     #define CH03 4
     #define CH04 5
     #define CH05 6
     #define CH06 7
     #define CH07 8
     #define CH08 9
     #define CH09 10
     #define CH10 11
     #define CH11 12
     #define CH12 13
     #define CH13 A0
     #define CH14 A1
     #define CH15 A2
     #define CH16 A3
     #define CH17 A4
     #define CH18 A5
    // Up to here for Arduino uno.
     #define CH19 A6
     #define CH20 A7
     #define CH21 A8
     #define CH22 A9
     #define CH23 A10
     #define CH24 A11
     #define CH25 A12
     #define CH26 A13
     #define CH27 A14
     #define CH28 A15
     #define CH29 22
     #define CH30 23
     #define CH31 24
     #define CH32 25
     #define CH33 26
     #define CH34 27
     #define CH35 28
     #define CH36 29
     #define CH37 30
     #define CH38 31
     #define CH39 32
     #define CH40 33
     #define CH41 34
     #define CH42 35
     #define CH43 36
     #define CH44 37
     #define CH45 38
     #define CH46 39
     #define CH47 40
     #define CH48 41
     
     int channels[] = {CH01,CH02,CH03,CH04,CH05 ,CH06,CH07,CH08,CH09,
     CH10,CH11,CH12,CH13,CH14,CH15,CH16,CH17,CH18,CH19,CH20,CH21,CH22,
     CH23,CH24,CH25,CH26,CH27,CH28,CH29,CH30,CH31,CH32,CH33,CH34,CH35,
     CH36,CH37,CH38,CH39,CH40,CH41,CH42,CH43,CH44,CH45,CH46,CH47,CH48};
    
     int incomingByte[CHANNEL_COUNT];
    
    int i = 0;     // Loop counter
    volatile unsigned long  timer_a = 0; // new line
    
    //setup the pins/ inputs & outputs
    void setup(){
    
      // enable the watchdog timer with a time of 1 second. If the board freezes, it will reset itself after 1 second.
      wdt_enable(WDTO_1S);
      
      // specifically for the UNO
      sei();  
    
    // initalize PWM Channels / Pins
     for (i=0; i < CHANNEL_COUNT; i++){
        pinMode(channels[i], OUTPUT);
      }
    
    // set all the realys to off to start with
    if (MODE == NOT_INVERTED) {
     for (i=0; i < CHANNEL_COUNT; i++){
         digitalWrite(channels[i], LOW);
    
     }
    }
    
    else {
     for (i=0; i < CHANNEL_COUNT; i++){
         digitalWrite(channels[i], HIGH);
     }
    }
    
     testSequence();
     
    // set up Serial according to the speed defined above.
      Serial.begin(VIXEN_COM_SPEED);
    }
    
    void loop()
    {
       if (Serial.available() >= (CHANNEL_COUNT+2)) {
         wdt_reset(); // resets the watchdog
         timer_a = millis (); // new line
         int uno = Serial.read();
         if (uno == 126){
           
           int dos = Serial.read();
           if (dos == 33){
       
             for (i=0; i < CHANNEL_COUNT; i++) {
                 // read each byte
              incomingByte[i] = Serial.read();
             }
    		 if (MODE == NOT_INVERTED) {
    			for (i=0; i < CHANNEL_COUNT; i++){
    			int value = incomingByte[i];
    			if (value <= 127) {
    				digitalWrite(channels[i], LOW);
    			}
    			else {
    				digitalWrite(channels[i], HIGH);
    			}
    			}
    		 }
    		 else {
    		 for (i=0; i < CHANNEL_COUNT; i++){
    			int value = incomingByte[i];
    			if (value < 127) {
    				digitalWrite(channels[i], HIGH);
    			}
    			else {
    				digitalWrite(channels[i], LOW);
    			}
    			}
    		 }
    
           }
         }
       }
    /*
    // Random mode code. Random mode starts if no serial input has been received in TIME_OUT millisenconds
       else {
         wdt_reset(); // resets the watchdog
         unsigned long diff = millis() - timer_a;
         if (diff >= TIME_OUT) {
           timer_a = millis ();
           int random_a = 0;
           for (i=0; i < CHANNEL_COUNT; i++){
             random_a = random(0, 2);
             if (random_a == 0) {
               digitalWrite(channels[i], LOW);
             }
             else {
               digitalWrite(channels[i], HIGH);
             }
           }
         }
       }
    */
    }
    
    void testSequence(){
    
    if (MODE == NOT_INVERTED) {
     for (i=0; i < CHANNEL_COUNT; i++){
       wdt_reset(); // resets the watchdog
       digitalWrite(channels[i], HIGH);
       delay (500);
       digitalWrite(channels[i], LOW);
     }
    }
    
    else {
     for (i=0; i < CHANNEL_COUNT; i++){
       wdt_reset(); // resets the watchdog
       digitalWrite(channels[i], LOW);
       delay (500);
       digitalWrite(channels[i], HIGH);
       }
     }
    }

  6. #6
    Join Date
    Jan 2019
    Posts
    82
    Post Thanks / Like

    Default Re: Removing Random from Victors sketch

    Quote Originally Posted by ScareCrowe View Post
    I commented out what *should* be the random code. I copied it from the original post and just commented out the random code section.
    Code:
    // This code was written by Victor Perez for doityourselfchristmas.com based on the code from Zparticle, Si_champion and Neil Tapp.
     // To adapt the code to your case, just change this top section, with the #define lines.
     
     // Includes the watchdog timer library
     #include <avr/wdt.h>
     
     // This sets how many channels will vixen be sending. Can be set to any number from 1 to 48 for Arduino Mega, and 1 to 18 for Arduino Uno.
     #define CHANNEL_COUNT 16
    
     // speed for the com port for talking with vixen. From 9600 to 115200. Use the same speed as set in Vixen.
     #define VIXEN_COM_SPEED 57600
     
     // Timeout waiting for serial input before going to random mode (in milliseconds).
     #define TIME_OUT 1000
     
     // If the relays turn On and Off opposite to Vixen sequence, change "#define MODE NOT_INVERTED" for "#define MODE INVERTED"
     #define NOT_INVERTED 0
     #define INVERTED 1
     #define MODE NOT_INVERTED
    
     // which pins control which channels
     // You can change these assignment to use different pins, but be very careful to not repeat the same pin number for 2 channels. 
     // DO NOT use pings 0 and 1, as those are for the serial port to talk to the computer.
     #define CH01 2
     #define CH02 3
     #define CH03 4
     #define CH04 5
     #define CH05 6
     #define CH06 7
     #define CH07 8
     #define CH08 9
     #define CH09 10
     #define CH10 11
     #define CH11 12
     #define CH12 13
     #define CH13 A0
     #define CH14 A1
     #define CH15 A2
     #define CH16 A3
     #define CH17 A4
     #define CH18 A5
    // Up to here for Arduino uno.
     #define CH19 A6
     #define CH20 A7
     #define CH21 A8
     #define CH22 A9
     #define CH23 A10
     #define CH24 A11
     #define CH25 A12
     #define CH26 A13
     #define CH27 A14
     #define CH28 A15
     #define CH29 22
     #define CH30 23
     #define CH31 24
     #define CH32 25
     #define CH33 26
     #define CH34 27
     #define CH35 28
     #define CH36 29
     #define CH37 30
     #define CH38 31
     #define CH39 32
     #define CH40 33
     #define CH41 34
     #define CH42 35
     #define CH43 36
     #define CH44 37
     #define CH45 38
     #define CH46 39
     #define CH47 40
     #define CH48 41
     
     int channels[] = {CH01,CH02,CH03,CH04,CH05 ,CH06,CH07,CH08,CH09,
     CH10,CH11,CH12,CH13,CH14,CH15,CH16,CH17,CH18,CH19,CH20,CH21,CH22,
     CH23,CH24,CH25,CH26,CH27,CH28,CH29,CH30,CH31,CH32,CH33,CH34,CH35,
     CH36,CH37,CH38,CH39,CH40,CH41,CH42,CH43,CH44,CH45,CH46,CH47,CH48};
    
     int incomingByte[CHANNEL_COUNT];
    
    int i = 0;     // Loop counter
    volatile unsigned long  timer_a = 0; // new line
    
    //setup the pins/ inputs & outputs
    void setup(){
    
      // enable the watchdog timer with a time of 1 second. If the board freezes, it will reset itself after 1 second.
      wdt_enable(WDTO_1S);
      
      // specifically for the UNO
      sei();  
    
    // initalize PWM Channels / Pins
     for (i=0; i < CHANNEL_COUNT; i++){
        pinMode(channels[i], OUTPUT);
      }
    
    // set all the realys to off to start with
    if (MODE == NOT_INVERTED) {
     for (i=0; i < CHANNEL_COUNT; i++){
         digitalWrite(channels[i], LOW);
    
     }
    }
    
    else {
     for (i=0; i < CHANNEL_COUNT; i++){
         digitalWrite(channels[i], HIGH);
     }
    }
    
     testSequence();
     
    // set up Serial according to the speed defined above.
      Serial.begin(VIXEN_COM_SPEED);
    }
    
    void loop()
    {
       if (Serial.available() >= (CHANNEL_COUNT+2)) {
         wdt_reset(); // resets the watchdog
         timer_a = millis (); // new line
         int uno = Serial.read();
         if (uno == 126){
           
           int dos = Serial.read();
           if (dos == 33){
       
             for (i=0; i < CHANNEL_COUNT; i++) {
                 // read each byte
              incomingByte[i] = Serial.read();
             }
    		 if (MODE == NOT_INVERTED) {
    			for (i=0; i < CHANNEL_COUNT; i++){
    			int value = incomingByte[i];
    			if (value <= 127) {
    				digitalWrite(channels[i], LOW);
    			}
    			else {
    				digitalWrite(channels[i], HIGH);
    			}
    			}
    		 }
    		 else {
    		 for (i=0; i < CHANNEL_COUNT; i++){
    			int value = incomingByte[i];
    			if (value < 127) {
    				digitalWrite(channels[i], HIGH);
    			}
    			else {
    				digitalWrite(channels[i], LOW);
    			}
    			}
    		 }
    
           }
         }
       }
    /*
    // Random mode code. Random mode starts if no serial input has been received in TIME_OUT millisenconds
       else {
         wdt_reset(); // resets the watchdog
         unsigned long diff = millis() - timer_a;
         if (diff >= TIME_OUT) {
           timer_a = millis ();
           int random_a = 0;
           for (i=0; i < CHANNEL_COUNT; i++){
             random_a = random(0, 2);
             if (random_a == 0) {
               digitalWrite(channels[i], LOW);
             }
             else {
               digitalWrite(channels[i], HIGH);
             }
           }
         }
       }
    */
    }
    
    void testSequence(){
    
    if (MODE == NOT_INVERTED) {
     for (i=0; i < CHANNEL_COUNT; i++){
       wdt_reset(); // resets the watchdog
       digitalWrite(channels[i], HIGH);
       delay (500);
       digitalWrite(channels[i], LOW);
     }
    }
    
    else {
     for (i=0; i < CHANNEL_COUNT; i++){
       wdt_reset(); // resets the watchdog
       digitalWrite(channels[i], LOW);
       delay (500);
       digitalWrite(channels[i], HIGH);
       }
     }
    }
    So I was "quoting out" by deleting the section probably why I had so many errors but by using asterisk it does accept program but does not stop random either

  7. #7
    Join Date
    Jan 2016
    Location
    Moline, IL
    Posts
    105
    Post Thanks / Like

    Default Re: Removing Random from Victors sketch

    Quote Originally Posted by mojuave1 View Post
    So I was "quoting out" by deleting the section probably why I had so many errors but by using asterisk it does accept program but does not stop random either
    I just want to make sure about something.....

    When you power the Arduino it should turn each relay on and off starting at #1 all the way to the last one you have, then it should stop. This is the testSequence() function.

    Once it does that does it continue to turn the relays on and off at random or does it stop after the last relay is done?

  8. #8
    Join Date
    Oct 2019
    Location
    SoCal
    Posts
    59
    Post Thanks / Like

    Default Re: Removing Random from Victors sketch

    Quote Originally Posted by ScareCrowe View Post
    I just want to make sure about something.....

    When you power the Arduino it should turn each relay on and off starting at #1 all the way to the last one you have, then it should stop. This is the testSequence() function.

    Once it does that does it continue to turn the relays on and off at random or does it stop after the last relay is done?
    Yes, it goes through the test sequence as you describe, and then moves on to play the random sequence. If that section (random) is removed, and there is no serial data input, then your lights should be in off state.

  9. #9
    Join Date
    Jan 2019
    Posts
    82
    Post Thanks / Like

    Default Re: Removing Random from Victors sketch

    Quote Originally Posted by LateraLiz View Post
    Yes, it goes through the test sequence as you describe, and then moves on to play the random sequence. If that section (random) is removed, and there is no serial data input, then your lights should be in off state.
    yes on power up it will go through the test but then right back to random as soon as I either shut down Vixen or unplug the USB cable. I verified and compiled sketch with random mode quoted out no errors so then uploaded it and got the done uploading. The arduino then tests the relays waits a bout a second then randomly turns on relays

  10. #10
    Join Date
    Jan 2016
    Location
    Moline, IL
    Posts
    105
    Post Thanks / Like

    Default Re: Removing Random from Victors sketch

    Quote Originally Posted by mojuave1 View Post
    yes on power up it will go through the test but then right back to random as soon as I either shut down Vixen or unplug the USB cable. I verified and compiled sketch with random mode quoted out no errors so then uploaded it and got the done uploading. The arduino then tests the relays waits a bout a second then randomly turns on relays
    OK, here is Victor's code I use for my 16 channel relay on an Uno. It is running now so I know it works. Test and Random are both disabled. It should work once you edit the pins to match your setup. Don't forget your header in Vixen.

    Code:
    // This code was written by Victor Perez for doityourselfchristmas.com based on the code from Zparticle, Si_champion and Neil Tapp.
     // To adapt the code to your case, just change this top section, with the #define lines.
     
     // Includes the watchdog timer library
     #include <avr/wdt.h>
     
     // This sets how many channels will vixen be sending. Can be set to any number from 1 to 48 for Arduino Mega, and 1 to 18 for Arduino Uno.
     #define CHANNEL_COUNT 16
    
     // speed for the com port for talking with vixen. From 9600 to 115200. Use the same speed as set in Vixen.
     #define VIXEN_COM_SPEED 57600
     
     // Timeout waiting for serial input before going to random mode (in milliseconds).
     #define TIME_OUT 1000
     
     // If the relays turn On and Off opposite to Vixen sequence, change "#define MODE NOT_INVERTED" for "#define MODE INVERTED"
     #define NOT_INVERTED 0
     #define INVERTED 1
     #define MODE INVERTED
    
     // which pins control which channels
     // You can change these assignment to use different pins, but be very careful to not repeat the same pin number for 2 channels. 
     // DO NOT use pings 0 and 1, as those are for the serial port to talk to the computer.
     #define CH01 A0
     #define CH02 A1
     #define CH03 A2
     #define CH04 A3
     #define CH05 A4
     #define CH06 A5
     #define CH07 2
     #define CH08 3
     #define CH09 4
     #define CH10 5
     #define CH11 6
     #define CH12 7
     #define CH13 8
     #define CH14 9
     #define CH15 10
     #define CH16 11
     
     int channels[] = {CH01,CH02,CH03,CH04,CH05,CH06,CH07,CH08,CH09,
     CH10,CH11,CH12,CH13,CH14,CH15,CH16};
    
     int incomingByte[CHANNEL_COUNT];
    
    int i = 0;     // Loop counter
    volatile unsigned long  timer_a = 0; // new line
    
    //setup the pins/ inputs & outputs
    void setup(){
    
      // enable the watchdog timer with a time of 1 second. If the board freezes, it will reset itself after 1 second.
      wdt_enable(WDTO_1S);
      
      // specifically for the UNO
      sei();  
    
    // initalize PWM Channels / Pins
     for (i=0; i < CHANNEL_COUNT; i++){
        pinMode(channels[i], OUTPUT);
      }
    
    // set all the realys to off to start with
    if (MODE == NOT_INVERTED) {
     for (i=0; i < CHANNEL_COUNT; i++){
         digitalWrite(channels[i], LOW);
    
     }
    }
    
    else {
     for (i=0; i < CHANNEL_COUNT; i++){
         digitalWrite(channels[i], HIGH);
     }
    }
    
    //DIABLE TEST SEQUENCE
     //testSequence();
     
    // set up Serial according to the speed defined above.
      Serial.begin(VIXEN_COM_SPEED);
      Serial.write("Vixen-Relay-Header-Victor_Perez");
    }
    
    void loop()
    {
       if (Serial.available() >= (CHANNEL_COUNT+2)) {
         wdt_reset(); // resets the watchdog
         timer_a = millis (); // new line
         int uno = Serial.read();
         if (uno == 126){
           
           int dos = Serial.read();
           if (dos == 33){
       
             for (i=0; i < CHANNEL_COUNT; i++) {
                 // read each byte
              incomingByte[i] = Serial.read();
             }
         if (MODE == NOT_INVERTED) {
          for (i=0; i < CHANNEL_COUNT; i++){
          int value = incomingByte[i];
          if (value <= 127) {
            digitalWrite(channels[i], LOW);
          }
          else {
            digitalWrite(channels[i], HIGH);
          }
          }
         }
         else {
         for (i=0; i < CHANNEL_COUNT; i++){
          int value = incomingByte[i];
          if (value < 127) {
            digitalWrite(channels[i], HIGH);
          }
          else {
            digitalWrite(channels[i], LOW);
          }
          }
         }
    
           }
         }
       }
    // Random mode code. Random mode starts if no serial input has been received in TIME_OUT millisenconds
       else {
         wdt_reset(); // resets the watchdog
    //BEGIN RANDOM - DISABLED
    /*
         unsigned long diff = millis() - timer_a;
         if (diff >= TIME_OUT) {
           timer_a = millis ();
           int random_a = 0;
           for (i=0; i < CHANNEL_COUNT; i++){
             random_a = random(0, 2);
             if (random_a == 0) {
               digitalWrite(channels[i], LOW);
             }
             else {
               digitalWrite(channels[i], HIGH);
             }
           }
         }
         */
    //END RANDOM
       }//end else
    }
    
    void testSequence(){
    
    if (MODE == NOT_INVERTED) {
     for (i=0; i < CHANNEL_COUNT; i++){
       wdt_reset(); // resets the watchdog
       digitalWrite(channels[i], HIGH);
       delay (500);
       digitalWrite(channels[i], LOW);
     }
    }
    
    else {
     for (i=0; i < CHANNEL_COUNT; i++){
       wdt_reset(); // resets the watchdog
       digitalWrite(channels[i], LOW);
       delay (500);
       digitalWrite(channels[i], HIGH);
       }
     }
    }

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •