Skip to content

Instantly share code, notes, and snippets.

@focalintent
focalintent / interp.cpp
Created October 26, 2016 18:39
Quick demo of what frame interpolation might look like
#include <FastLED.h>
#define NUM_LEDS 60
// how many frames per second you want your animation to be. Your total
// update rate will be ANIM_FPS * STEPS
#define ANIM_FPS 30
// the number of steps you want between each frame - should be a power
// of 2 to keep things sane - e.g. 2,4,8,16,32,64
@focalintent
focalintent / Lighting up one by one
Last active June 4, 2016 10:32
Lighting up one by one
#include "FastLED.h"
#include <SPI.h>
#define NumPixels 1500 // number of LEDs in strip - count starts at 0, not 1
#define Datapin 11 // datapin - green on apa102
#define Clockpin 13 // clockpin - blue on apa102
#define DataRate_Mhz 15
CRGB leds[NumPixels];
int g, r, b, z;
int head=-1, tail=(head-6);
#include "FastLED.h"
template <EOrder RGB_ORDER=RGB>
class NetworkWriteController : public CPixelLEDController<RGB_ORDER> {
public:
public NetworkWriteController() {
// TODO: Modify the constructor to take other options that you might want/need (esp8266 ip
// address? etc...)
}
@focalintent
focalintent / gist:6a936de0502c98bbba6c
Last active December 10, 2015 06:19
On C++11 range loops vs. C loops in ARM (FastLED random musings)

Comparing the guts of loops between C style loops and C++ ranged loops:

Right now - the runtime of this:

CRGBArray<100> leds;
...
for(CRGB & pixel : leds) { pixel = CRGB::Black; }
#ifndef FASTDELEGATE_H
#define FASTDELEGATE_H
#include <cstring>
#include <type_traits>
#include <cassert>
#include <cstddef>
#include <memory>
#include <new>
#include <utility>
@focalintent
focalintent / private.xml
Last active November 12, 2015 01:15
Private.xml definition for switching between english/russian input sources depending on which keyboard I'm using. (I may switch this over to the right cmd key so that I can manually switch layouts around, for example, if I want to be able to switch between english/russian easily)
<?xml version="1.0"?>
<!-- private.xml definition for Karabiner - https://pqrs.org/osx/karabiner/index.html.en -->
<root>
<inputsourcedef>
<name>MY_RUSSIAN</name>
<inputsourceid_prefix>com.apple.keylayout.Russian</inputsourceid_prefix>
</inputsourcedef>
<inputsourcedef>
<name>MY_ENGLISH</name>

Keybase proof

I hereby claim:

  • I am focalintent on github.
  • I am focalintent (https://keybase.io/focalintent) on keybase.
  • I have a public key whose fingerprint is EF70 3635 60D7 FBF4 EC57 684A 5088 E8B0 D972 0875

To claim this, I am signing this object:

@focalintent
focalintent / scale8.md
Last active August 29, 2015 14:26
On scale8, correctness, and cycle counting on avr

FastLED is about more than just pushing data out to leds as quickly as possible. It is also about providing the fastest supporting function (math, color maniuplation, etc...) while still remaining accurate. Mark has done an amazing job with many of the math functions, including fast trig functions that are ~98% accurate, and the core of the scaling functions. These scaling functions are what allow us to do things like the non-destructive, 0 overhead scaling and color adjustments in the library.

scale8 - the background

The basic scaling function in FastLED is scale8. It lets you scale an 8-bit value by another 8-bit value. It's a percentage of sorts, but from 0-255 instead of 0-100. So, for example, scale8(64,128) will give you 32. Scaling is something that gets used a lot in led work, so it is important that it be fast. The C version of scale8 takes advantage of some properties of binary math to do it's magic (while avoiding division), let's take a look:

uint8_t scale8(uint8_t i, fract8 s
@focalintent
focalintent / parseIntArgh.md
Last active December 25, 2023 14:14
A gumbling about Arduino's Serial.parseInt implementation

A quick lesson in performance tuning. In the arduino code base, people will often use Serial.parseInt to read integer data from a Serial stream, and someone was asking me about the overhead involved. So, I decided to take a look for them. First, I looked at the implementation of parseInt:

long Stream::parseInt()
{
  return parseInt(NO_SKIP_CHAR); // terminate on first non-digit character (or timeout)
}

Ok, so it calls through to another function, adding a skip character that means "no skip character". Here's a first red flag. So, let's look at that function:

@focalintent
focalintent / gist:f1b1fc3c024b04fabbaf
Last active August 29, 2015 14:20
APA102VController
template <uint8_t DATA_PIN, uint8_t CLOCK_PIN, EOrder RGB_ORDER = BGR, uint8_t SPI_SPEED = DATA_RATE_MHZ(24)>
class APA102VController : public CLEDController {
typedef SPIOutput<DATA_PIN, CLOCK_PIN, SPI_SPEED> SPI;
SPI mSPI;
void startBoundary() { mSPI.writeWord(0); mSPI.writeWord(0); }
void endBoundary(int nLeds) { int nBytes = (nLeds/64); do { mSPI.writeByte(0xFF); mSPI.writeByte(0x00); mSPI.writeByte(0x00); mSPI.writeByte(0x00); } while(nBytes--); }
inline void writeLed(uint8_t b0, uint8_t b1, uint8_t b2, uint8_t v) __attribute__((always_inline)) {
mSPI.writeByte(0xE0 | (v&0x1F)); mSPI.writeByte(b0); mSPI.writeByte(b1); mSPI.writeByte(b2);