Skip to content

Instantly share code, notes, and snippets.

@kasperkamperman
Last active March 31, 2016 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kasperkamperman/90e6a4f84e5eb2b84b64 to your computer and use it in GitHub Desktop.
Save kasperkamperman/90e6a4f84e5eb2b84b64 to your computer and use it in GitHub Desktop.
Test FastLED.show timing on different Particle Photon pins.
/*
Measurement of the FastLED.show() routine.
Soft SPI is only supported till now on the Photon.
However non-SPI pins seem to be 140us faster then when using the SPI pins.
Using those SPI pins in hardware design might be interesting for future compatibility
when hardware SPI gets supported.
Below the timing test of different pin combinations. The APA102 is updated at 16Mhz.
*/
// A3/A5 max 593us
// D0/D1 max 456us
// D2/D3 max 453us
// A0/A1 max 456us
// A1/A2 max 452us
// A2/A3 max 549us (A2 clock, A3 data)
// A3/A2 max 496us (A3 clock, A2 data)
// A3/A4 max 592us
// A4/A5 max 592us
// A5/A6 max 593us
// A6/A7 max 592us
#include "application.h"
#include "FastLED/FastLED.h"
FASTLED_USING_NAMESPACE;
#include "LumiBase.h"
#define NUM_LEDS 128
#define DATA_PIN D3
#define CLOCK_PIN D2
CRGB leds[NUM_LEDS];
// debug duration
unsigned long t1; // for measuring purposes
unsigned long t2; // for measuring purposes
unsigned long t3 = 0; // for measuring purposes
int counter = 0;
void setup() {
delay(500);
Serial.begin(57600);
FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN, BGR, DATA_RATE_MHZ(16)>(leds, NUM_LEDS);
FastLED.setMaxRefreshRate(0);
FastLED.setBrightness(255);
FastLED.setDither(0);
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB(0,0,0);
}
}
void setTime() {
t1 = micros();
}
void printTime() {
t2 = micros()-t1;
if(t2>t3) t3 = t2;
Serial.print(F("update time: "));
Serial.print(t3);
Serial.print(" ");
Serial.println(t2);
}
void loop() {
if(counter>255) {
counter = 0;
}
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB(counter,0,255-counter);
}
counter++;
setTime();
FastLED.show();
printTime();
delay(500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment