mi-schi / arduino-kitt-scanner Goto Github PK
View Code? Open in Web Editor NEWKnight Rider KITT scanner with speed setting and 17 programs
Knight Rider KITT scanner with speed setting and 17 programs
First try to have all functions minimized for Attiny24:
byte lightPins[8] = {5, 4, 3, 1, 0, 8, 9, 10};
byte allLights[8] = {0, 1, 2, 3, 4, 5, 6, 7};
byte halfLights[2][4] = {{0, 1, 2, 3}, {4, 5, 6, 7}};
byte lights[3][4][2] = {
{{0, 7}, {1, 6}, {2, 5}, {3, 4}},
{{0, 4}, {1, 5}, {2, 6}, {3, 7}},
{{3, 4}, {2, 5}, {1, 6}, {0, 7}}
};
byte speedPin = A6;
volatile byte program = 0;
void setup() {
for (int i=0; i<8; i++) {
pinMode(lightPins[i], OUTPUT);
}
pinMode(2, INPUT);
attachInterrupt(1, programSwitch, RISING);
}
void loop() {
if (program == 1) {
// flasher
flasher();
} else if (program == 2 || program == 3) {
// police 2 times, police
for (byte s = 0; s < 2; s++) {
toogleHalfLights(s);
if (program == 3) {
toogleHalfLights(s);
}
}
} else if (program == 5 || program == 6 || program == 7 || program == 11 || program == 12) {
// out to in splitted/full, left to right splitted, in to out splitted/full
lightsToMidFull(lights[program-5]);
} else if (program == 13) {
// left to right two lights
byte l[4] = {0, 1, 6, 7};
twoLeds(l, 1, 7);
} else if (program == 14) {
// right to left two lights
byte l[4] = {7, 6, 1, 0};
twoLeds(l, 6, 0);
} else if (program == 8) {
// flasher 2 times
flasher();
sensoredDelay();
flasher();
} else if (program == 9) {
// snake
snake(0, 7);
} else if (program == 10) {
// snake reverse
snake(7, 0);
} else {
kitt(0, 7);
kitt(7, 0);
}
}
void kitt(byte start, byte end) {
for (int i=start; i<end; i++) {
digitalWrite(lightPins[i], HIGH);
sensoredDelay();
digitalWrite(lightPins[i+1], HIGH);
sensoredDelay();
digitalWrite(lightPins[i], LOW);
sensoredDelay();
}
}
void twoLeds(byte sL[4], byte start, byte end) {
digitalWrite(lightPins[sL[0]], 1);
sensoredDelay();
digitalWrite(lightPins[sL[1]], 1);
sensoredDelay();
for (int i=start; i<end; i++) {
digitalWrite(lightPins[i-1], 0);
digitalWrite(lightPins[i], 1);
digitalWrite(lightPins[i+1], 1);
sensoredDelay();
}
digitalWrite(lightPins[sL[6]], 0);
sensoredDelay();
digitalWrite(lightPins[sL[7]], 0);
sensoredDelay();
}
void snake(byte s, byte e) {
for (int i=s; i<=e; i++) {
digitalWrite(lightPins[i], 1);
sensoredDelay();
}
for (int i=e; i<=s; i++) {
digitalWrite(lightPins[i], 0);
sensoredDelay();
}
}
void toogleHalfLights(byte s) {
for (byte i = 0; i < 2; i++) {
switchLights(halfLights[s], i);
sensoredDelay();
}
}
void lightsToMidFull(byte lights[4][2]) {
byte maxI = 4;
if (program < 10) {
maxI = 3;
}
for (int i=0; i<maxI; i++) {
switchLights(lights[i], HIGH);
sensoredDelay();
if (program < 10) {
switchLights(lights[i], LOW);
}
}
for (int i=maxI; i>0; i--) {
switchLights(lights[i], HIGH);
sensoredDelay();
if (program < 10) {
switchLights(lights[i], LOW);
}
}
}
void flasher() {
switchLights(allLights, 1);
sensoredDelay();
switchLights(allLights, 0);
sensoredDelay();
}
void switchLights(byte lights[], byte value) {
for (byte i = 0; i < (sizeof(lights)/sizeof(int)); i++) {
digitalWrite(lightPins[lights[i]], value);
}
}
void sensoredDelay() {
delay(analogRead(speedPin) + 50);
}
void programSwitch() {
program++;
if (program == 16) {
program = 0;
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.