Page 3 of 3 FirstFirst 123
Results 21 to 27 of 27

Thread: Execute vixen sequence into arduino without vixen ?

  1. #21
    Join Date
    Dec 2012
    Location
    Hudson MA
    Posts
    2,886
    Post Thanks / Like

    Default Re: Execute vixen sequence into arduino without vixen ?

    Space is the problem. The ESP has almost no storage compared to what a sequence would take up.


    2018 - Moving and going to visit my Daughter in New Zealand. Most likely I will be dark or nearly dark, Some static stuff that is simple to put up.

  2. #22
    Join Date
    Nov 2015
    Location
    The Netherlands
    Posts
    58
    Post Thanks / Like

    Default Re: Execute vixen sequence into arduino without vixen ?

    I had the idea of being able to switch sequence while "playing". I needed it for a drama performance of my missus..... On stage there is a "stove" which has to be "burning" all the time. Once she puts a paper in it, it has to "burn" harder. So i asked my neighbour, who is a programmer if he could change Barnabybear's code to make the above possible. (i am not able to do so myself ) He came with the code I will post at the end of this reply. When the esp8266 is switched on it plays sequence 00000001, when the button is pushed is starts to play sequence 00000002. When sequence 00000002 is over, it resumes playing sequence 00000001

    Here is the code:

    Code:
     
    /*
      The following code is still under development by Barnabybear, use it in your show at your own risk..
      The code is slightly changed by Michiel Kersjes to be able to switch sequence with the push of a button
    */
    
    #include <SPI.h>
    #include <SD.h>
    #include <FastLED.h>
    #include <ESP8266WiFi.h> // comment out if not using ESP8266
    
    // START OF USER SET UP INFOMATION
    
    #define NUM_LEDS 72 // the number of leds attached.
    #define DATA_PIN 2 // the pin used for data out.
    //const int chipSelect = 15;  // only needed if you don't use GPIO 15 as CS (Chip Select).
    const int buttonPin = 16; 
    
    int buttonState = 0;         
    
    //IMPORTANT - the file name needs to be in the format 8.3 chars.
    //When you save the file to the SD card give it an 8 char file name.
    //Edit the file name and remove the 'q' from .fseq to leave .fse
    
    const char FSEQ_Data_File[13] = "00000001.fse"; // replace xxxxxxxx with your file name.
    long int First_Channel = 0;  // 0 = first channel number in .FSEQ file.
    bool Loop_Set = 1; // 0 = play once, 1 = loop.
    bool Debug = 1; // minimum debug.
    bool PSEQ_Headder_Debug = 1; // debug .PSEQ headder.
    // END OF USER SET UP INFOMATION
    
    long int Data_Offset;  // start of data in .FSEQ file (length of headder) (read from file).
    long int Number_Channels;  //  total number of channels in .FSEQ file (read from file).
    long int Step_Lenght;  // number of frames in .FSEQ file (read from file).
    int Frame_Time;  // FPS of of frames in .FSEQ file (read from file).
    unsigned long Time_Show = 0;
    unsigned long Time_Now;
    int Current_LED;  // variable for led looping.
    long int Current_Step;  // code current step / frame number.
    
    File dataFile;  // required by SD.h.
    CRGB leds[NUM_LEDS]; // required by FastLED.
    
    const char FSEQ_Data_FileBTN[13] = "00000002.fse"; // replace xxxxxxxx with your file name.
    long int First_ChannelBTN = 0;  // 0 = first channel number in .FSEQ file.
    bool Loop_SetBTN = 1; // 0 = play once, 1 = loop.
    bool DebugBTN = 1; // minimum debug.
    bool PSEQ_Headder_DebugBTN = 1; // debug .PSEQ headder.
    // END OF USER SET UP INFOMATION
    
    long int Data_OffsetBTN;  // start of data in .FSEQ file (length of headder) (read from file).
    long int Number_ChannelsBTN;  //  total number of channels in .FSEQ file (read from file).
    long int Step_LenghtBTN;  // number of frames in .FSEQ file (read from file).
    int Frame_TimeBTN;  // FPS of of frames in .FSEQ file (read from file).
    unsigned long Time_ShowBTN = 0;
    unsigned long Time_NowBTN;
    int Current_LEDBTN;  // variable for led looping.
    long int Current_StepBTN;  // code current step / frame number.
    
    File dataFileBTN;  // required by SD.h.
    
    /////////////////////////////////////////////////////////
    
    void setup()
    {
      Serial_Initialize(); // Initialize serial.
      WiFi.mode(WIFI_OFF); // comment out if not using ESP8266
      FastLED_Initialize(); // Initialize FastLED.
      SD_Initialize(); // Initialize SD card.
      pinMode(buttonPin, INPUT);     
      FESQ_Headder_Read();
      FESQ_Headder_ReadBTN();
    }
    /////////////////////////////////////////////////////////
    
    void loop()
    {
      if (dataFile) { // check file open.
        while (Current_Step < (Step_Lenght + 1)) { // if NOT at the end of the sequence.
          Serial.print("H ");
          Serial.println(Current_Step);
          
          buttonState = digitalRead(buttonPin);
          if (buttonState == HIGH) {     
            Serial.println("=================");
    // ======================================-----------------------------
            Current_StepBTN = 0;
            if (dataFileBTN) { // check file open.
              while (Current_StepBTN < (Step_LenghtBTN + 1)) { // if NOT at the end of the sequence.
              Serial.print("BTN ");
              Serial.println(Current_StepBTN);
           
              dataFileBTN.seek(((Data_OffsetBTN) - 1) + First_ChannelBTN + ((Number_ChannelsBTN) * Current_StepBTN)); // first read postion = (after the file headder) + (miss out unused channels). Subcequent read postion = as above + (the number of channels in file * the number of previous reads).
              for (Current_LEDBTN = 0; Current_LEDBTN < NUM_LEDS; Current_LEDBTN++) { // loop based on number of channels / pixels to read
                leds[Current_LEDBTN].setRGB(dataFileBTN.read(), dataFileBTN.read(), dataFileBTN.read()); // read 3 current pixel values into FastLED buffer.
              }
              while (!((millis() - Time_ShowBTN) > (Frame_TimeBTN))) {
                delay(1);
              }
              Time_ShowBTN = millis();
              FastLED.show();
              //      Serial.println(Current_Step); // debug print.
              Current_StepBTN++; // add 1 to the current step postion.
          //      break;
            }
          }
      //=====================================================----------------------------
            Serial.println("=================");
           // delay(100);
          } 
          dataFile.seek(((Data_Offset) - 1) + First_Channel + ((Number_Channels) * Current_Step)); // first read postion = (after the file headder) + (miss out unused channels). Subcequent read postion = as above + (the number of channels in file * the number of previous reads).
          for (Current_LED = 0; Current_LED < NUM_LEDS; Current_LED++) { // loop based on number of channels / pixels to read
            leds[Current_LED].setRGB(dataFile.read(), dataFile.read(), dataFile.read()); // read 3 current pixel values into FastLED buffer.
          }
          while (!((millis() - Time_Show) > (Frame_Time))) {
            delay(1);
          }
          Time_Show = millis();
          FastLED.show();
          //      Serial.println(Current_Step); // debug print.
          Current_Step++; // add 1 to the current step postion.
          //      break;
        }
      }
      if (Loop_Set) {
        Current_Step = 0;
      }
    }
    /////////////////////////////////////////////////////////
    
    //*************** void Serial_Initialize ***************//
    void Serial_Initialize() {
      // Open serial communications and wait for port to open:
      Serial.begin(115200); // debug print.
      while (!Serial) {
        ; // wait for serial port to connect. Needed for Leonardo only.
      }
      Serial.println("Serial initialized @ 115200.");
    }
    /////////////////////////////////////////////////////////
    
    //*************** void FastLED_Initialize ***************//
    void FastLED_Initialize() {
      FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); // FastLED
      for (Current_LED = 0; Current_LED < NUM_LEDS; Current_LED++) {
        leds[Current_LED].setRGB(0, 0, 0);
        FastLED.show();
      }
      Serial.println("FastLED initialized & set to all off."); // debug print.
    }
    /////////////////////////////////////////////////////////
    
    //*************** void SD_Initialize ***************//
    void SD_Initialize() {
      Serial.print("Initializing SD card... "); // debug print.
      if (!SD.begin()) {  // see if the card is present and can be initialized.
        Serial.println("Card failed, or not present"); // debug print.
        return;
      }
      Serial.println("Card initialized."); // debug print.
    }
    /////////////////////////////////////////////////////////
    
    //*************** void FESQ_Headder_Read ***************//
    void FESQ_Headder_Read() {
      Serial.print("FSEQ file header details."); // debug print.
      dataFile = SD.open(FSEQ_Data_File); // open file.
      if (dataFile) { // check file open.
        //-----------------------------------------
        dataFile.seek(4); // set read pionter to correct byte.
        Data_Offset = (dataFile.read()); // read LSB.
        Data_Offset = Data_Offset + (dataFile.read() * 256); // read MSB & add to LSB.
        while (PSEQ_Headder_Debug) { // debug print.
          Serial.println(); // debug print.
          Serial.print("Data Offset: "); // debug print.
          Serial.print(Data_Offset); // debug print.
          Serial.print(" "); // debug print.
          break;
        }
        //-----------------------------------------
        dataFile.seek(10); // set read pionter to correct byte.
        Number_Channels = (dataFile.read()); // read LSB.
        Number_Channels = Number_Channels + (dataFile.read() * 256); // read MSB & add to LSB.
        while (PSEQ_Headder_Debug) { // debug print.
          Serial.println(); // debug print.
          Serial.print("Channels: "); // debug print.
          Serial.print(Number_Channels); // debug print.
          Serial.print(" "); // debug print.
          break;
        }
        //-----------------------------------------
        dataFile.seek(14); // set read pionter to correct byte.
        Step_Lenght = (dataFile.read()); // read LSB.
        Step_Lenght = Step_Lenght + (dataFile.read() * 256); // read MSB & add to LSB.
        while (PSEQ_Headder_Debug) { // debug print.
          Serial.println(); // debug print.
          Serial.print("Step Length: "); // debug print.
          Serial.print(Step_Lenght); // debug print.
          Serial.print(" "); // debug print.
          break;
        }
        //-----------------------------------------
        dataFile.seek(18); // set read pionter to correct byte.
        Frame_Time = (dataFile.read()); // Read FPS.
        while (PSEQ_Headder_Debug) { // debug print.
          Serial.println(); // debug print.
          Serial.print("Frame Timing: "); // debug print.
          Serial.print(Frame_Time, DEC); // debug print.
          Serial.println(); // debug print.
          break;
        }
        //-----------------------------------------
        while (Debug) { // debug print.
          Serial.print(FSEQ_Data_File); // debug print.
          Serial.println(" and variables set."); // debug print.
          delay(10);
          break;
        }
      }
      // if the file isn't open, pop up an error:
      else {
        while (Debug) { // debug print.
          Serial.print("error opening "); // debug print.
          Serial.println(FSEQ_Data_File); // debug print.
          break;
        }
      }
      return;
    }
    
    //*************** void FESQ_Headder_Read ***************//
    void FESQ_Headder_ReadBTN() {
      Serial.print("FSEQ BTN file header details."); // debug print.
      dataFileBTN = SD.open(FSEQ_Data_FileBTN); // open file.
      if (dataFileBTN) { // check file open.
        //-----------------------------------------
        dataFileBTN.seek(4); // set read pionter to correct byte.
        Data_OffsetBTN = (dataFileBTN.read()); // read LSB.
        Data_OffsetBTN = Data_OffsetBTN + (dataFileBTN.read() * 256); // read MSB & add to LSB.
        while (PSEQ_Headder_DebugBTN) { // debug print.
          Serial.println(); // debug print.
          Serial.print("Data BTN Offset: "); // debug print.
          Serial.print(Data_OffsetBTN); // debug print.
          Serial.print(" "); // debug print.
          break;
        }
        //-----------------------------------------
        dataFileBTN.seek(10); // set read pionter to correct byte.
        Number_ChannelsBTN = (dataFileBTN.read()); // read LSB.
        Number_ChannelsBTN = Number_ChannelsBTN + (dataFileBTN.read() * 256); // read MSB & add to LSB.
        while (PSEQ_Headder_DebugBTN) { // debug print.
          Serial.println(); // debug print.
          Serial.print("Channels BTN: "); // debug print.
          Serial.print(Number_ChannelsBTN); // debug print.
          Serial.print(" "); // debug print.
          break;
        }
        //-----------------------------------------
        dataFileBTN.seek(14); // set read pionter to correct byte.
        Step_LenghtBTN = (dataFileBTN.read()); // read LSB.
        Step_LenghtBTN = Step_LenghtBTN + (dataFileBTN.read() * 256); // read MSB & add to LSB.
        while (PSEQ_Headder_DebugBTN) { // debug print.
          Serial.println(); // debug print.
          Serial.print("Step Length BTN: "); // debug print.
          Serial.print(Step_LenghtBTN); // debug print.
          Serial.print(" "); // debug print.
          break;
        }
        //-----------------------------------------
        dataFileBTN.seek(18); // set read pionter to correct byte.
        Frame_TimeBTN = (dataFileBTN.read()); // Read FPS.
        while (PSEQ_Headder_DebugBTN) { // debug print.
          Serial.println(); // debug print.
          Serial.print("Frame Timing BTN: "); // debug print.
          Serial.print(Frame_TimeBTN, DEC); // debug print.
          Serial.println(); // debug print.
          break;
        }
        //-----------------------------------------
        while (DebugBTN) { // debug print.
          Serial.print(FSEQ_Data_FileBTN); // debug print.
          Serial.println(" and variables set BTN."); // debug print.
          delay(10);
          break;
        }
      }
      // if the file isn't open, pop up an error:
      else {
        while (DebugBTN) { // debug print.
          Serial.print("error opening BTN "); // debug print.
          Serial.println(FSEQ_Data_FileBTN); // debug print.
          break;
        }
      }
      return;
    }
    D0 is pulled down with a 10k resistor to ground. Button connected to 3,3V and to D0. When button closes sequence 0000002 starts.
    Errors for fun only.

  3. #23
    Join Date
    Dec 2011
    Location
    UK S80 postcode
    Posts
    1,306
    Post Thanks / Like

    Default Re: Execute vixen sequence into arduino without vixen ?

    Hi, cool and thanks for posting the code for others. Out of interest; how many pixels? What frame rate are you using? How long is the sequnce? What size are the files?

  4. #24
    Join Date
    Nov 2015
    Location
    The Netherlands
    Posts
    58
    Post Thanks / Like

    Default Re: Execute vixen sequence into arduino without vixen ?

    I tested with 2 1-minute sequences. Until now i tried only 50 pixels. Filesize is 179KB at 20 frames/sec.

    Sharing code doubles the fun, doesn't it?
    Errors for fun only.

  5. #25
    Join Date
    Nov 2015
    Location
    The Netherlands
    Posts
    58
    Post Thanks / Like

    Default Re: Execute vixen sequence into arduino without vixen ?

    @Barnabybear: Especially with short sequences we (my neigbour and i) experience a short white flash when the sequence loops. My neighbour found out that by changing
    Code:
        while (Current_Step < (Step_Lenght + 1)) { // if NOT at the end of the sequence.
    to
    Code:
    while   (Current_Step < (Step_Lenght)) { // if NOT at the end of the sequence.
    fixed the problem. Now we are asking ourselves why the + 1 is in the code. Could you please explain?
    Last edited by kockie; 07-10-2018 at 04:18 PM.
    Errors for fun only.

  6. #26
    Join Date
    Dec 2011
    Location
    UK S80 postcode
    Posts
    1,306
    Post Thanks / Like

    Default Re: Execute vixen sequence into arduino without vixen ?

    Hi, it’s some time since I wrote this and looking back at it now I can’t see why the ‘+1’ is needed; it just adds one un-needed step to the loop.

    If the ‘Step_Length’ is equal to 100, the loop ‘0 to 99’ should loop 100 times and drop out when it gets to 100. It looks like I was having a moment when I wrote this line – sorry. The short white flash would be when the code reads from empty memory locations which would most likely be FF/256 by default resulting in a full white flash for that time period.

    Glad you’re having fun with this.

  7. #27
    Join Date
    Nov 2015
    Location
    The Netherlands
    Posts
    58
    Post Thanks / Like

    Default Re: Execute vixen sequence into arduino without vixen ?

    excuses not needed I'm glad you made this sketch. I've used it on a couple of occasions. Last times the "button" version. Thanks for your effort!
    Errors for fun only.

Page 3 of 3 FirstFirst 123

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
  •