You are viewing mrmeval

Previous Entry | Next Entry

Knight rider or other blinky toy

Cougar cub
With the ability to independently control 16 LEDs this is pretty flexible.

Rather than a full blown Arduino board the LEDs can be run stand alone from a bare minimum board. The serial control could be done from the same board with a USB<->TTL cable. It mimics a serial port to the PC. I may have time to actually stuff all this in a board. Maybe a holiday Cylon ornament since I used red and green LEDs. Really gorgeous red and green LEDs.

The schematic for the LEDs is here PDFs suck and I could not get this the way I wanted it. I'll keep trying.

I am curious as to why the bits are reversed from what the datasheet says but I'm not too worried about it. If you use the code post it, if you redact or otherwise masticate it I'd like to see it but it's not GPL it's public domain. The code is specifically for the Arduino IDE, I'm unfamiliar with directly compiling it with any other tool.



/*
Dual hef4794 knightrider toy

by Mr. Meval public domain 11/25/2007

Inspired by the works of the following
but changed beyond recognition I think.

*http://www.arduino.cc/en/Tutorial/LEDDriver
* (copyleft) 2005 K3, Malmo University
* @author: David Cuartielles, Marcus Hannerstig
* @hardware: David Cuartielles, Marcos Yarza
* @project: made for SMEE - Experiential Vehicles
*/

int data = 9;
int strob = 8;
int clock = 10;
int oe = 11;
int count = 0;
int dato = 0;
int ack = 13;

void setup()
{
pinMode(data, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(strob, OUTPUT);
pinMode(oe, OUTPUT);
pinMode(ack, OUTPUT);
digitalWrite(oe, LOW);
}

void loop()
{
digitalWrite(ack, HIGH);
dato = 1;
for (int i = 0 ; i < 16 ; i++){
shiftOut(data, clock, LSBFIRST, dato>>8);
shiftOut(data, clock, LSBFIRST, dato);
dato = dato<<1;
digitalWrite(oe, LOW);
digitalWrite(strob, HIGH);
digitalWrite(oe, HIGH);
digitalWrite(strob, LOW);
delay(50); // waits for a moment
digitalWrite(ack, LOW);
}
dato = 32768;
for (int i = 16 ; i > 0 ; i--){
shiftOut(data, clock, LSBFIRST, dato>>8);
shiftOut(data, clock, LSBFIRST, dato);
dato = unsigned (dato)>>1;
digitalWrite(oe, LOW);
digitalWrite(strob, HIGH);
digitalWrite(oe, HIGH);
digitalWrite(strob, LOW);
delay(50); // waits for a moment
digitalWrite(ack, LOW);
}

}

/*
Serially control one of 16 bits
by Mr. Meval, public domain 11/25/2007
*/

int data = 9;
int strob = 8;
int clock = 10;
int oe = 11;
int count = 0;
int ack = 13;
int incomingByte;


void setup()
{
pinMode(data, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(strob, OUTPUT);
pinMode(oe, OUTPUT);
pinMode(ack, OUTPUT);
digitalWrite(oe, LOW);
Serial.begin(9600);
}

void write16(int x) {
shiftOut(data, clock, LSBFIRST, x>>8);
shiftOut(data, clock, LSBFIRST, x);
digitalWrite(oe, LOW);
digitalWrite(strob, HIGH);
digitalWrite(oe, HIGH);
digitalWrite(strob, LOW);
}

void loop()
{
digitalWrite(ack, HIGH);

if (Serial.available() > 0) {
incomingByte = Serial.read();
Serial.println(incomingByte);
switch (incomingByte) {
case 49:
write16 (1);
break;

case 50:
write16 (2);
break;

case 52:
write16 (4);
break;

case 56:
write16 (8);
break;

case 97:
write16 (16);
break;

case 98:
write16 (32);
break;

case 99:
write16 (64);
break;

case 100:
write16 (128);
break;

case 101:
write16 (256);
break;

case 102:
write16 (512);
break;

case 103:
write16 (1024);
break;

case 104:
write16 (2048);
break;

case 105:
write16 (4096);
break;

case 106:
write16 (8192);
break;

case 107:
write16 (16384);
break;

case 108:
write16 (32768);
break;

case 48:
write16 (0);
break;

case 126:
write16 (65535);
break;

default:
write16 (0);
break;
}
delay(50);
}
}


/*
Since I can't seem to read two bytes in a row, I encode the bits with letters
1 = 1, 2 = 2, 4 = 4, 8 = 8, a=16, b=32, c=64, d=128, e=256, f=512, g=1024, h=2048, i=4096, j=8192, k=16384, l=32768

zero sets them all off
tilda sets them all on

*/

Tags:

Comments

( 2 comments — Leave a comment )
2percentright
Nov. 26th, 2007 05:50 am (UTC)
what language is this written in?
mrmeval
Nov. 27th, 2007 11:24 pm (UTC)
A variant of C or C++ specific to that microcontroller.
( 2 comments — Leave a comment )

Profile

Cougar cub
mrmeval
mrmeval

Latest Month

May 2014
S M T W T F S
    123
45678910
11121314151617
18192021222324
25262728293031
Powered by LiveJournal.com
Designed by chasethestars