NeoPixelPSI – Using

So, you’ve got your new PSI boards and have them mounted in your droid, now you need to get them to do things!

Code Examples

ReelTwo

My preferred solution is to use the ReelTwo library, however this may be overkill as its designed to run all your dome lighting (and more) from a single Arduino Mega. This is how I’ve been running my droid for the last few years and it works great whilst also vastly simplifying the wiring, especially the power. Feel free to give me a shout if you want to go over my setup. (Note to self, good idea to do a write up about it!)

Adding the NeoPixelPSI to an existing ReelTwo setup is a case of adding the include file, and specifying the PSI pins you used.

#include “dome/NeoPixelPSI.h”
NeoPixelPSI fpsi(3);
NeoPixelPSI rpsi(4);

By default, the PSI will be the colours for the front PSI. You can change the colours in the setup() function with:

rpsi.set_color(1,0,255,0);
rpsi.set_color(2,255,255,0);

This will set the rear PSI to the standard colours. Colours are specified in RGB values (0-255). The first value is 1 to set the first colour, and 2 to set the second.

Flash your code and plugging in your PSIs (with power off!) and you’ll have a couple of standard PSIs for your droid.

FlthyMcNasty HP Boards

Another option is to use some spare headers on your FlthyHP system. This is a great solution if you already use his HP system (and if you don’t, why not?! I use it, implemented in ReelTwo). All you have to do is take the example code from my github and plug in the PSI boards. The format is similar to the ReelTwo library, with the PSI defaulting to the standard front PSI behaviour and needing to set the colours in the setup function.

Standalone

If for some reason you want to just use a standalone arduino to power your PSIs, I have done a breakout board that accepts a pro mini arduino and has some simple input/output headers to accept power and up to 4 PSI boards.

The code is functionally the same as both the FlthyHP and ReelTwo libraries, so just needs a bare minimum for changes. The code in my github will run two HPs as per the standard for R2.

Functions

The PSI code is written in an object oriented style, with each PSI being treated as an object. There are a few functions available to change the look/feel of your PSI

set_color(color, r, g, b)

As it sounds, this sets the colour of the PSI. If color = 1, then the rgb values are used for the first colour. If color = 2, then they are to set the second colour. These are used in the standard swipe animation. The RGB values are all between 0 and 255.

set_brightness(brightness)

This accepts a value from 0-255, with 0 being off (why would you set that?) and 255 being blinding. A typical value is around 20-40. The lower the value, the lower the current draw.

set_speed(speed)

Set the speed the colours swipe from one side to another. This is in milliseconds, specifying the time between each ‘frame’ of the animation. So a lower number is actually a quicker swipe. Typical value is about 75ms.

set_delay(delay)

Use this to set the time between each swipe. Again set in milliseconds, and actually produces a random delay between the animations of between <delay> and <delay*4>. A typical value will be around 1500ms.

Effects

As a work in progress, I have also written a couple of simple effects with the idea being these can be triggered by an i2c command or similar.

do_random(cycles, pulse_speed)

This will flash each pixel on the PSI at a random colour and slowly over <cycles> the number of pixels that are flashing will reduce until the PSI is black. Useful for a ‘malfunction’ effect. <speed> is the number of milliseconds between each frame of animation.

do_pulse(pulses, pulse_speed, r, g, b)

A nice little effect that will pulse a PSI at a set colour, something like a heart beat. <pulses> is the number of pulses to do, <pulse_speed> is the delay between each frame (20 frames per pulse) in milliseconds. The RGB values are set between 0 and 255.

Note: Its colour, not color, but to make things easier with existing libraries such as the Adafruit Neopixel one, I spelt all the functions and variables in the code as color to keep it consistent. That hurt!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.