A site dedicated to Twichels, and things they (ok mostly me) are interested in.
 

Larson Scanner Code Page

Code as installed in car as of 11-23-14.
Note # of LEDs is 40. I have 39 LEDs + 1st one for RGB in encoder (WS2811 LED driver).
I had to cut LED String to fit my car. The Instructables page has code for the full 60 LED String. I also cleaned up the comments a little bit for the Instructable.

//From bildr article: http://bildr.org/2012/08/rotary-encoder-arduino/

#include <Adafruit_NeoPixel.h>

#define N_LEDS 40
#define PIN 6
// #define PIN 7 //encoder LED

Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_LEDS, PIN, NEO_GRB + NEO_KHZ800);

//these pins can not be changed 2/3 are special pins
int encoderPin1 = 2;
int encoderPin2 = 3;

volatile int lastEncoded = 0;
volatile int encoderValue = 0; //changed 10-20-14 and 10-26-14

long lastencoderValue = 0;

int lastMSB = 0;
int lastLSB = 0;

void setup() {

strip.begin();
int pos = 1, dir = 1; // Position, direction of "eye"

Serial.begin (9600);

pinMode(encoderPin1, INPUT);
pinMode(encoderPin2, INPUT);

digitalWrite(encoderPin1, HIGH); //turn pullup resistor on
digitalWrite(encoderPin2, HIGH); //turn pullup resistor on

//call updateEncoder() when any high/low changed seen
//on interrupt 0 (pin 2), or interrupt 1 (pin 3)
attachInterrupt(0, updateEncoder, CHANGE);
attachInterrupt(1, updateEncoder, CHANGE);

}

int pos = 1, dir = 1; // Position, direction of "eye"
void loop(){
//Do stuff here
int count =0;
count = (encoderValue / 4);

// Serial.println(encoderValue);
Serial.println(count);


int j;
long colorb = 0; // added 10-20-14
long colorg = 0;
long colorr =0; //changed 10-22-14
// int count;
colorb = colorb + abs(encoderValue); //added 10-20-14 blue

colorg = colorb + 2*abs(encoderValue);

colorr = colorb + 4*abs(encoderValue);


int red [13] = { 255,255,255,255,128,0,0,0,0,0,127,255,255};
int red1[13] = { 128,128,204,204,102,0,0,0,0,0,102,204,204};
int red2[13] = { 32,16,153,153,76,0,0,0,0,0,76,153,153};
int green [13] = {255,0,0,0,0,0,127,255,255,255,255,255,127};
int green1[13] = { 128,0,0,0,0,0,102,64,204,128,204,204,102};
int green2[13] = { 32,0,0,0,0,0,76,32,153,16,153,153,76};
int blue [13] = { 255,0,127,255,255,255,255,255,0,0,0,0,0};
int blue1[13] = { 128,0,102,204,204,128,204,32,102,0,0,0,0};
int blue2[13] = { 32,0,76,153,153,16,153,32,76,0,0,0,0};


// if (colorb > 2550) colorb=0; //rotate through colors loop
if (colorb > 255) colorg = colorg ++;
// if (colorb > 255) {colorb = 0;}
if (colorg >255) colorr = colorr++;
// if (colorg > 255) {colorg = 0;}
// if (colorr > 255) colorb=0;
// if (colorr > 255) colorg=0;
// if (colorr > 255) colorr=0;

// Draw 5 pixels centered on pos. setPixelColor() will clip any
// pixels off the ends of the strip, we don't need to watch for that.
strip.setPixelColor(0,(red[count]),(green[count]),(blue[count])); // ENCODER
strip.setPixelColor(pos - 2,(red2[count]),(green2[count]),(blue2[count])); // red2 green2 blue2 from array
strip.setPixelColor(pos - 1, (red1[count]),(green1[count]),(blue1[count])); // red1 green1 blue1
strip.setPixelColor(pos , (red[count]),(green[count]),(blue[count])); // Center pixel is brightest
strip.setPixelColor(pos + 1, (red1[count]),(green1[count]),(blue1[count])); // red1 green1 blue1
strip.setPixelColor(pos + 2,(red2[count]),(green2[count]),(blue2[count])); // red2 green2 blue2

strip.show();
delay(30);

// Rather than being sneaky and erasing just the tail pixel,2111111111111111111111111111
// it's easier to erase it all and draw a new one next time.
for(j=-2; j<= 2; j++) strip.setPixelColor(pos+j, 0);

// Bounce off ends of strip
pos += dir;
if(pos < 2) {
pos = 3;
dir = -dir;
} else if(pos >= strip.numPixels()) {
pos = strip.numPixels() - 2;
dir = -dir;
}
}

 

 

 

 

 

twichel.com home link  
 
Home   Projects Page   Larson Scanner Page

Questions and comments should be mailed to the Webmaster

last updated 12-9-14