Cylon Eye

JediPuju

New Member
Joined
Jun 9, 2009
Messages
47
Ive been dormant here for a while but Ive been mucking around with PICs and electronics etc for my models, and with the release of the mobius cylon raider out there (quaralane kicking off nicely I see) I thought this would be an Ideal little project to flex my programming.

I started my refit enterprise circuit in MPASM assembler. But I also bought an Arduino nano at the time I bought my Pickit 3 to see what the fuss is all about. Well In about an hour and with absolutely no previous experience with arduino (but I do program lots for work) I had a decent prototype up and running! MUCH easier than assembler! 8)

Got the roving eye working with a nice fade either side, and also a couple of leds which have a nice subtle flicker to them for the engines (doesnt show well in the video unfortunately). Might tweak the animation slightly but its a good start for someone.

CylonEye

And here is the code if you wish to try this out:


/*
CylonEye
Simple Sketch for Cylon Kits
Lee Fitzsimmons March 2012

You are free to use this code as you wish,
Just dont blame me if something blows up :D

*/

//num2pin contains maps the position in the pattern to its pin num
int num2pin[] = {3,5,6,9,10,11};
//pins for the engines
int engine1 = 7;
int engine2 = 8;

//the animation frames in an array.
int sweep[][6] = {
{255,60,10,0,0,0},
{60,255,60,10,0,0},
{10,60,255,60,10,0},
{0,10,60,255,60,10},
{0,0,10,60,255,60},
{0,0,0,10,60,255},
{0,0,10,60,255,60},
{0,10,60,255,60,10},
{10,60,255,60,10,0},
{60,255,60,10,0,0}
};
int seqlen = 10;
int statelen = 5;
int curseq = 0;

unsigned long time;
unsigned long prevtime = 0;
unsigned long interval = 80;

void setup() {
//pwm pins dont require setting direction
pinMode(engine1, OUTPUT);
pinMode(engine2, OUTPUT);
randomSeed(analogRead(0));
}

void loop() {

//we use the running time in miliseconds to determine the
//speed at which the animation runs
time = millis();
if(time - prevtime > interval) {
prevtime = time;
//set each led to the current animation 'frame'
for(int t=0; t <= statelen; t++) {
analogWrite(num2pin[t], sweep[curseq][t]);
}
//increment frame, loop if at end
curseq++;
if(curseq > seqlen -1) {
curseq = 0;
}
}

//engines
int rand = random(255);
analogWrite(engine1, rand);
rand = random(255);
analogWrite(engine2, rand);

}



Keep Jumpin', and watch out for those frakkin' toasters ;D
 
Indeed, the resulting effect looks awesome.
Thank You very much for sharing the code!
 
first of all i'd like to congratulate you on this achievement, i have no idea how you did it and i sure dont understand that computer code stuff.

is there a way to slow down the cycle rate for the red LED's as it appears to be running at a fast rate... i think to make it look more in line with the cylons it would need to run slower.

would just like to add if you make this as a kit and sell it, i'd buy it !
 
Same here... :D

A little bit too fast... TO be in the right rythm with the cylons, 2 times slower maybe ? ;)
 
Jimi said:
first of all i'd like to congratulate you on this achievement, i have no idea how you did it and i sure dont understand that computer code stuff.

is there a way to slow down the cycle rate for the red LED's as it appears to be running at a fast rate... i think to make it look more in line with the cylons it would need to run slower.

would just like to add if you make this as a kit and sell it, i'd buy it !

I would like to do that kind of thing one day, I quite like the idea of producing lighting kits. :D

Absolutely the effect can be slowed down, and I tend to agree with both of you. There is a variable in there that does it.
Also, the circuit can be rigged up to a pot which could be used to change the rate dynamically.

Only thing though, is that a slower speeds, with this many LEDs the effect starts to look a little clunky I think. Ill have to scale it down to the Moebius kit size with FO's and see what it looks like. Also with arduino I think you are limited to 6 LEDs that can make use of the inbuilt pulse width modulation, which is the method used to dim the leds.

You can see in the code the analogWrite function takes a value to apply to a specific pin on the mcu.
With arduino however, you can only use this function on 6 of the available pins, from what I read.
To add PWM on more pins, I think you have to make this code yourself, which is considerably more difficult.
Any AVR / ATMega gurus here to put me right?

Im now starting to turn my attention to the Pickit 3 I have and the stack of 16F628A's I have lying around. Im going to now attempt to write this in MPASM assembler so I can have more leds on the go. Also, I originally wanted to learn the PIC stuff but have been tempted by the ease of arduino. But for me, I like a challenge ;)

Ill post more as I learn and develop more ..
 
Just think that you don't need to have the led directly seen... You'll have a "screen", a "visor", possibily smoked... :D
 
Are you guys still speaking English? LOL ;D

I have the utmost admiration to anyone who can program using this type of code.

I program CNC milling machines and the 'G' code programming we use is very basic but understandable to a moron like me, but this stuff...... :eek:

I dont understand it and i never will but i'm loving the results.

Great stuff buddy.

Gag
 

Latest posts

Back
Top