help with interfacing esp8266 SPIFFS

I don't get it. The code in posts #17 and #19 is identical up to the line with the error message. The only difference are after the error message, and so can't be the cause of the error message. There must be something we are missing here.

Okay so it took me a bit of research. (I needed a break) But now I’m at the same place I was with the SD cards.

#include "FS.h"
#include "ESP8266WiFi.h"

int x = 32;
int y = 12;
int numOfLeds = x * y;
int CompareFrame = 0;
int delayBetweenFrames = 1000;
const int buttonPin = D8;
int buttonState = 0;
bool boolButtonPressed = false;

void setup() {
  Serial.begin(115200);

  if (!SPIFFS.begin()) {
    Serial.println("An Error has occurred while mounting SPIFFS");
    return;
  }
}

void loop() {
  buttonPress();
}

void setLEDs() {
  File file = SPIFFS.open("/test.txt", "r");
  if (!file) {
    Serial.println("Failed to open file for reading");
    return;
  }
  Serial.println("File Content:");
  while (file.available()) {
    //Serial.write(file.read());
    int numberOfFrames = file.parseInt();
    int frame = file.parseInt();
    int ledNumber = file.parseInt();
    byte red = file.parseInt();
    byte green = file.parseInt();
    byte blue = file.parseInt();
    file.read();
    file.read();
    Serial.print(ledNumber);
    Serial.print(", ");
    Serial.print(red);
    Serial.print(", ");
    Serial.print(green);
    Serial.print(", ");
    Serial.println(blue);

    if (CompareFrame == frame) {
      //      leds[ledNumber] = CRGB(red, green, blue);
    }
    else {
      delay(delayBetweenFrames);
      CompareFrame = CompareFrame + 1;
    }
  }
  file.close();
}

void buttonPress() {
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH) {
    boolButtonPressed == true;
    delay(10);
    CompareFrame == 0;
    setLEDs();
  }
  else {
    boolButtonPressed == false;
  }
}

void clearLEDs() {
  for (int i = 0; i < numOfLeds; i++)
  {
    //    leds[i] = CRGB(0, 0, 0);
  }
}

My problem now I that I need the file to read itself over and over to act as an animation. At the moment it just reads the file once. And when I press the button to start the animation over it adds an extra delay.

You can use

file.seek(0,SeekSet);

to return to the start of the currently open file.

PS. have a look at this link. It describes these commands, but it also says that SPIFFS is "depricated" which means it will stop being developed, and new projects should use "littleFS" which has almost all the same commands. Might be a good idea to change to litteFS now, before you get much further.

Ok I took a break after finishing another project and researched a bit. I’ve rewritten some code and I’m way more confident now. I’ve now separated the files in a way that will make it easier for the project. I currently can’t test the full functionality at the moment cause I only have 4 neopixels but I have one currently wired in and I keep watching the Serial Monitor. I do have one problem I can’t seem to get rid of. I’m trying to switch out the animations by using a button but it won’t register all of my button presses.

//#include <FS.h>
#include <FastLED.h>
#include "LittleFS.h"
#include "ESP8266WiFi.h"

#define NUM_LEDS 1
#define DATA_PIN D7

CRGB leds[NUM_LEDS];

const int buttonPin = D8;
int buttonState = 0;

void setup() {
  Serial.begin(115200);
  LittleFS.begin();
  if (!LittleFS.begin()) {
    Serial.println("LittleFS mount failed");
    return;
  }
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  
  pinMode(buttonPin, INPUT);

}

void loop() {
  buttonState = digitalRead(buttonPin);
  delay(500);

  if(buttonState % 2 == 0){
    Serial.print("case1");
    setLEDs("/test0.txt");
    delay(1000);
    setLEDs("/test1.txt");
    delay(1000);
    setLEDs("/test2.txt");
    delay(1000);
    setLEDs("/test3.txt");
  }
  if(buttonState % 2 == 1){
    Serial.print("case2");
    setLEDs("/dim0.txt");
    delay(1000);
    setLEDs("/dim1.txt");
    delay(1000);
    setLEDs("/dim2.txt");
    delay(1000);
    setLEDs("/dim3.txt");
  }
}

void setLEDs(const char * path) {
  Serial.printf("Reading file: %s\n", path);

  File file = LittleFS.open(path, "r");
  if (!file) {
    Serial.println("Failed to open file for reading");
    return;
  }

  Serial.print("Read from file: ");
  while (file.available()) {
      int batterySaver = 3;
      int ledNumber = file.parseInt();
      byte red = file.parseInt();
      byte green = file.parseInt();
      byte blue = file.parseInt();
      file.read();
      file.read();
      
      red = red / batterySaver;
      green = green / batterySaver;
      blue = blue / batterySaver;

      Serial.print(" ledNumber:");
      Serial.print(ledNumber);
      Serial.print(" red:");
      Serial.print(red);
      Serial.print(" green:");
      Serial.print(green);
      Serial.print(" blue:");
      Serial.println(blue);
      
      leds[0] = CRGB(red, green, blue);
      FastLED.show();
      delay(5);
      }
  file.close();
}

void clearLEDs() {
  leds[0] = CRGB(0, 0, 0);
}

johnscott:
it won't register all of my button presses.

  delay(500);

...
      delay(5);

There's your answer!

Okay I’ve rewritten the code to use millis() for the button presses. But It’s just looping past the conditions I put in place (as if I were holding down the button)

//#include <FS.h>
#include <FastLED.h>
#include "LittleFS.h"
#include "ESP8266WiFi.h"

#define NUM_LEDS 1
#define DATA_PIN D7

CRGB leds[NUM_LEDS];

const int buttonPin = D8;
unsigned long startMillis;
unsigned long currentMillis;
const unsigned long period = 1000;
int buttonCounter;

void setup() {
  Serial.begin(115200);
  LittleFS.begin();
  if (!LittleFS.begin()) {
    Serial.println("LittleFS mount failed");
    return;
  }
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  pinMode(buttonPin, INPUT);
  startMillis = millis();  //initial start time
}

void loop() {
  buttonPress();

  if(buttonCounter % 3 == 0){
    Serial.print("case1");
    setLEDs("/test0.txt");
    delay(1000);
    setLEDs("/test1.txt");
    delay(1000);
    setLEDs("/test2.txt");
    delay(1000);
    setLEDs("/test3.txt");
  }
  if(buttonCounter % 3 == 1){
    Serial.print("case2");
    setLEDs("/dim0.txt");
    delay(1000);
    setLEDs("/dim1.txt");
    delay(1000);
    setLEDs("/dim2.txt");
    delay(1000);
    setLEDs("/dim3.txt");
  }
  if(buttonCounter % 3 == 2){
    clearLEDs();
  }
}

void setLEDs(const char * path) {
  //Serial.printf("Reading file: %s\n", path);

  File file = LittleFS.open(path, "r");
  if (!file) {
    Serial.println("Failed to open file for reading");
    return;
  }

  Serial.print("Read from file: ");
  while (file.available()) {
      int batterySaver = 3;
      int ledNumber = file.parseInt();
      byte red = file.parseInt();
      byte green = file.parseInt();
      byte blue = file.parseInt();
      file.read();
      file.read();
      
      red = red / batterySaver;
      green = green / batterySaver;
      blue = blue / batterySaver;

      Serial.print(" ledNumber:");
      Serial.print(ledNumber);
      Serial.print(" red:");
      Serial.print(red);
      Serial.print(" green:");
      Serial.print(green);
      Serial.print(" blue:");
      Serial.println(blue);
      
      leds[0] = CRGB(red, green, blue);
      FastLED.show();
      delay(5);
      }
  file.close();
}


void buttonPress() {
  currentMillis = millis();
  if (currentMillis - startMillis >= period)
  {
    buttonCounter++;
    startMillis = currentMillis;
  }
  
}

void clearLEDs() {
  leds[0] = CRGB(0, 0, 0);
  for(int j = 0; j < 100; j++){
    Serial.println("case 3");
  }
  delay(10000);

}

The uses of delay() I picked out in my last post were just examples. There are still many examples of delay() in your code. During delay(), nothing else happens. Not even detecting a button press. Code is executed one line at a time. When it comes to a delay(), it stops for the specified time, and there are no other lines of code being executed somewhere in the background. Long delays mean missed button presses. Short delays are not so bad, unless they are inside a for/while loop, in which case they add up to long delays.

In your attempt to use millis(), I'm not sure you really understand what you wrote, or copied. Try "running"the code in your head or on paper and see what it does.

I think you lost the line of code that checks the button pin.