BetterPhotonButton (community library)


Name Value
Name BetterPhotonButton
Version 0.1.6
Installs 1304
License Apache License, Version 2.0
Author Kevin R. Smith
Download .tar.gz
All Versions 0.1.6, 0.1.5, 0.1.4, 0.1.3, 0.1.2, 0.1.1, 0.1.0

Classes to simplify use of Particle's InternetButton with Photon.

Example Build Testing

Device OS Version:

This table is generated from an automated build. Success only indicates that the code compiled successfully.

Library Read Me

This content is provided by the library maintainer and has not been validated or approved.


Replacement for Particle's InternetButton library specific to the Photon


After reading through the code to InternetButton from Particle I wanted to fix a few things. Instead I ended up creating a replacement.

BetterPhotonButton only works with the Photon (not the Core). The LED driver class only works with WS2812 LEDs (the ones on the InternetButton).


  • There is no use of the delay() function in BetterPhotonButton.

  • Button presses and releases have debounce handling built in and can trigger a callback function.

  • The LED/Pixel classes support animations. Write your own or use one of the 17 built in animations.

  • The animations support custom color palettes.

  • LEDs can be set with separate r, g, b values or with a combined value (like html colors).

  • The Accelerometer class supports a callback method which is called when the InternetButton starts or stops moving. The class also provides angle, azimuth, pitch, and roll calculations. It uses a state machine when starting up to also avoid using delay().

All of the above is accomplished by an update() method on BetterPhotonButton. Just add update(millis()) to the loop() method and BetterPhotonButton classes take care of the rest.


The below is the example code from AnimateAccel, it simply rotates a gradient color palette so color 0 stays at the top.

#include "BetterPhotonButton.h"


BetterPhotonButton bb = BetterPhotonButton();
PhotonADXL362Accel *accel;

void gradientTop(PixelAnimationData *data) {
float step = data->pixelCount - (accel->getAzimuth() / (360 / data->pixelCount));
for (int idx = 0; idx < data->pixelCount; idx++) {
data->pixels[idx] = data->paletteColor(((step + idx) * data->paletteCount()) / data->pixelCount);

void setup() {
accel = bb.startAccelerometer(1000/60);  // start accelerometer with a update rate of 60x per second
bb.startPixelAnimation(&gradientTop, &paletteRainbow);

void loop() {

The key to this code being bb.setup() and bb.update(...). Every BetterPhotonButton needs to call these two for the library to function properly.



See above.


Use the buttons to cycle through a variety of sample animations.


Use the buttons to increment/decrement/reset which LED is lit up.


Cycle through 11 'tunes' using the buttons. One tune per LED.


The simplest BetterPhotonButton example. Simple gradiant across all the LEDs.

#include "BetterPhotonButton.h"

BetterPhotonButton bb = BetterPhotonButton();

void setup() {
bb.rainbow(250); // cycle rainbow every 250ms (indefinitely)

void loop() {

The rainbow(...) function exists as an carryover from Particle's InternetButton library. All it does is call startPixelAnimation(&animation_gradient, &paletteRainbow, cycle, duration);


Example of playing notes while animating the LEDs


  • It is possible to use the PhotonWS2812Pixel and Animations classes directly to support any chain of WS8212 pixel LEDs. Just use the BetterPhotonButton class as an example.
  • See BetterPhotonButton::updateAnimation and the global pixelRing specifically


Copyright 2017 The Brynwood Team, LLC.

Browse Library Files