Skip to content

Instantly share code, notes, and snippets.

@focalintent
focalintent / pixel_node.ino
Created May 1, 2014 19:19
pixel_node ported to FastLED
/***************************************************************************
*
* Title : Arduino based Art-Net -> LED Pixel, Digital LED Strip gateway
* Version : v 0.2 beta
* Last updated : 17.12.2012
* Target : Arduino mega 2560, Arduino mega 1280, Arduino UNO *** Arduino IDE v0023 ***
* Pixel number : Arduino mega 340 pixels (2 universes), Arduino UNO 170 pixels (1 universe)
* Driver support : TM1803, TM1804, TM1809, TM1812, WS2811
* Author : Toni Merino - merino.toni at gmail.com
* Web : www.deskontrol.net/blog
@focalintent
focalintent / GridMaps
Last active March 1, 2023 07:08
Showing off some pixel mapping and rotating
// base GridMap class. Allows from mapping from an X x Y grid of
// T values to an MX x MY grid of T values (where
// MX and MY are greater than X and Y respectively), using linear
// interpolation to fill in the gaps. Optionally allows for rotating
// around the center point. Subclasses should provide an implementation
// for the interpolate method, appropriate to the type of data being mapped
template<int X, int Y, int MX, int MY, class T> class AbstractGridMap {
int revcosval,revsinval;
uint8_t angle;
@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);
@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 / 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

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 / 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>
#ifndef FASTDELEGATE_H
#define FASTDELEGATE_H
#include <cstring>
#include <type_traits>
#include <cassert>
#include <cstddef>
#include <memory>
#include <new>
#include <utility>
@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; }
#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...)
}