SirPalesAlot
New member
I'm a complete beginner when it comes to Arduino code (I really don't know what I'm doing). Somehow, I managed to find the code I needed to make my LED matrix function using Glediator/Jinx! and I even managed to get the saved file to load from the SD card. The issue I have now is getting the saved file to actually loop from the beginning once it's finished playing. I usually try to find the answer on my own by searching, but so far, I haven't been able to find what I'm looking for. I'm not sure if I am just overlooking the needed information somewhere or I am not searching for the right things. So, my question is, how do I manage to get the loaded file to restart/loop once it is finished?
Board: Teensy 3.5 with an OctoWS2811 adapter.
Board: Teensy 3.5 with an OctoWS2811 adapter.
Code:
// Glediator example with OctoWS2811, by mortonkopf
//
// https://forum.pjrc.com/threads/33012-Gladiator-with-OctoWS2811-working-example
#include <OctoWS2811.h>
#include <SPI.h>
#include <SD.h>
const int ledsPerStrip = 272;
const int NUM_LEDS = 1632;
DMAMEM int displayMemory[ledsPerStrip*6];
int drawingMemory[ledsPerStrip*6];
const int config = WS2811_GRB | WS2811_800kHz;
OctoWS2811 leds(ledsPerStrip, displayMemory, drawingMemory, config);
File myfile;
// Use these for the SD+Wiz820 or other adaptors
//#define SDCARD_CS_PIN 4
//#define SDCARD_MOSI_PIN 11
//#define SDCARD_SCK_PIN 13
// Use these with the Teensy 3.5 & 3.6 SD card
#define SDCARD_CS_PIN BUILTIN_SDCARD
#define SDCARD_MOSI_PIN 11 // not actually used
#define SDCARD_SCK_PIN 13 // not actually used
// Use these with the Teensy Audio Shield
//#define SDCARD_CS_PIN 10
//#define SDCARD_MOSI_PIN 7
//#define SDCARD_SCK_PIN 14
void setup() {
leds.begin();
leds.show();
SPI.setMOSI(SDCARD_MOSI_PIN);
SPI.setSCK(SDCARD_SCK_PIN);
if (!(SD.begin(SDCARD_CS_PIN))) {
// stop here, but print a message repetitively
while (1) {
Serial.println("Unable to access the SD card");
delay(500);
}
}
}
int serialGlediator() {
while (!Serial.available()) {}
return Serial.read();
}
int fileGlediator() {
return myfile.read();
}
void loop() {
byte r,g,b;
int i;
if (!myfile) {
// need to open the file
myfile = SD.open("myanim.dat");
if (!myfile) {
Serial.println("could not open the file! :(");
delay(500);
return;
}
}
while (fileGlediator() != 1) {}
for (i=0; i < NUM_LEDS; i++) {
b = fileGlediator();
r = fileGlediator();
g = fileGlediator();
leds.setPixel(i, Color(r,g,b));
}
leds.show();
}
/* Helper functions */
// Create a 24 bit color value from R,G,B
unsigned int Color(byte r, byte g, byte b)
{
return (((unsigned int)b << 16) | ((unsigned int)r << 8) | (unsigned int)g);
}