Last active
May 23, 2019 01:23
-
-
Save remcoder/7293022 to your computer and use it in GitHub Desktop.
ATTiny85 KITT scanner with 12 LEDs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A KITT scanner made out of 12 deep red LEDs hooked up to nothing but an ATTiny85. | |
// It leverages the magic of charlieplexing to enable the ATTiny to drive those 12 LED's with just 4 pins. | |
// | |
// video: http://www.youtube.com/watch?v=MYvrKLcG-Vg | |
const int blue = 0; | |
const int green = 1; | |
const int red = 2; | |
const int white = 3; | |
int pins[] = {blue,green,red,white}; | |
int countPins = sizeof(pins) / sizeof(int); | |
int led_source[] = {blue , green, blue, red , blue , white, green, red , green, white, red , white}; | |
int led_sink[] = {green, blue , red, blue, white, blue , red , green, white, green, white, red}; | |
int countLeds = sizeof(led_source)/sizeof(int); | |
int pos = 0; | |
int maxPos = countLeds -1; | |
int period = 1000; | |
int i=2; | |
int j=1; | |
int k=0; | |
int id = 1; | |
int jd = 1; | |
int kd = 1; | |
void setup() { } | |
void loop() { | |
for (int l=0 ; l<12 ; l++) | |
{ | |
charlie(k, 64); | |
charlie(j, 256); | |
charlie(i, 512); | |
} | |
i+=id; | |
if (i == (countLeds-1) || i == 0) | |
id = -id; | |
j+=jd; | |
if (j == (countLeds-1) || j == 0) | |
jd = -jd; | |
k+=kd; | |
if (k == (countLeds-1) || k == 0) | |
kd = -kd; | |
} | |
void charlie(int led, int us) | |
{ | |
int source = led_source[led]; | |
int sink = led_sink[led]; | |
for(int p=0 ; p<countPins; p++) | |
pinMode(pins[p], INPUT); | |
pinMode(source, OUTPUT); | |
pinMode(sink, OUTPUT); | |
digitalWrite(source, HIGH); | |
digitalWrite(sink, LOW); | |
delayMicroseconds(us); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
do you have a schematic?