Arduino Micro - The Setup
And here's the code to run it. Im running off pins 4-7 in the code, so this should port over to other Arduino models with no problem; ignore the 3bit and 4bit bit methods, just me prepping for the final project.
LED Array Binary Counting Code
[sourcecode language="java"]
int timeDigits[4][4] = {
{4,5,6,7},
{4,5,6,7}, // Fill these in later
{4,5,6,7},// with the proper pins
{4,5,6,7}
};
void setup() {
Serial.begin(9600);
pinMode(timeDigits[1][1], OUTPUT);
pinMode(timeDigits[1][2], OUTPUT);
pinMode(timeDigits[1][3], OUTPUT);
pinMode(timeDigits[1][4], OUTPUT);
}
void set4BitBinaryDigit(int timeDigits[], int binaryRow[], int index) {
Serial.print("Binary ");
Serial.print(index);
Serial.print(": ");
Serial.print(binaryRow[0]);
Serial.print(binaryRow[1]);
Serial.print(binaryRow[2]);
Serial.println(binaryRow[3]);
Serial.println(" ");
digitalWrite(timeDigits[0], binaryRow[0]);
digitalWrite(timeDigits[1], binaryRow[1]);
digitalWrite(timeDigits[2], binaryRow[2]);
digitalWrite(timeDigits[3], binaryRow[3]);
}
void set3BitBinaryDigit(int timeDigits[], int binaryRow[]) {
digitalWrite(timeDigits[1], binaryRow[1]);
digitalWrite(timeDigits[2], binaryRow[2]);
digitalWrite(timeDigits[3], binaryRow[3]);
}
void set2BitBinaryDigit(int timeDigits[], int binaryRow[]) {
digitalWrite(timeDigits[2], binaryRow[2]);
digitalWrite(timeDigits[3], binaryRow[3]);
}
void loop() {
int binaryMatrix[10][4] = {
{0,0,0,0}, // 0
{0,0,0,1}, // 1
{0,0,1,0}, // 2
{0,0,1,1}, // 3
{0,1,0,0}, // 4
{0,1,0,1}, // 5
{0,1,1,0}, // 6
{0,1,1,1}, // 7
{1,0,0,0}, // 8
{1,0,0,1},// 9
};
for (int i = 0; i < 1000; ++i)
{
for (int i = 0; i <= 9; ++i) {
set4BitBinaryDigit(timeDigits[1], binaryMatrix[i], i);
delay(800);
}
}
}
[/sourcecode]
And a little video footage showing it in action.
Binary Counting With LEDs - Video Footage
http://youtu.be/hRk3L37uTxs
[...] Step one for making a binary clock accomplished. Now I just need some more LEDs to finish the project. I had a lot of fun with this 2 hour project so I'll be nice and share. I present the 4 LED arr... [...]
ReplyDelete