Arduino Tutorial: How to Make a LED Cube
VIDEO
hello, In this tutorial you will learn to make LED Cube using arduino board based on atmega chip. is cheap and simple to use. To make this prototype I am using:
Led
Resistor
atmega8l-8pu
Jumper wire
Breadboard
Schema
Code
Code
int Anode[4]={A5,A4,A3,A2}; //led Anodes
int Led[16]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,A0,A1}; //led rows
void setup()
{
for(int i = 0; i<16; i++)
{
pinMode(Led[i], OUTPUT); //setting rows to ouput
}
for(int i = 0; i<4; i++)
{
pinMode(Anode[i], OUTPUT); //setting Anodes to output
}
}
void loop()
{
allOff();
EdgeDown();
flicker();
EdgeDown1();
flicker();
turnhor();
turnver();
turnverr();
}
//turn all off
void allOff()
{
allledOff();
allanodeOff();
}
void turnver()
{
for(int y = 0; y<6; y++)
{
for(int i = 0; i<4; i++)
{
digitalWrite(Anode[i], 1);
turnallledOn();
turnallledOff();
digitalWrite(Anode[i], 0);
}
}
}
void turnverr()
{
allanodeOff();
allledOn();
for(int y = 0; y<6; y++)
{
turnallanodeOn();
turnallanodeOff;
}
}
void turnhor()
{
allanodeOn();
for(int y = 0; y<5; y++)
{
turnallledOn();
turnallledOff();
}
}
void EdgeDown()
{
allanodeOn();
for(int x = 600; x != 0; x -=50)
{
allledOff();
digitalWrite(Led[0], 0);
digitalWrite(Led[1], 0);
digitalWrite(Led[2], 0);
digitalWrite(Led[3], 0);
delay(x);
digitalWrite(Led[0], 1);
digitalWrite(Led[1], 1);
digitalWrite(Led[2], 1);
digitalWrite(Led[3], 1);
digitalWrite(Led[4], 0);
digitalWrite(Led[13], 0);
digitalWrite(Led[12], 0);
digitalWrite(Led[11], 0);
delay(x);
digitalWrite(Led[4], 1);
digitalWrite(Led[13], 1);
digitalWrite(Led[12], 1);
digitalWrite(Led[11], 1);
digitalWrite(Led[10], 0);
digitalWrite(Led[15], 0);
digitalWrite(Led[14], 0);
digitalWrite(Led[5], 0);
delay(x);
digitalWrite(Led[10], 1);
digitalWrite(Led[15], 1);
digitalWrite(Led[14], 1);
digitalWrite(Led[5], 1);
digitalWrite(Led[6], 0);
digitalWrite(Led[7], 0);
digitalWrite(Led[8], 0);
digitalWrite(Led[9], 0);
delay(x);
}
}
void EdgeDown1()
{
allanodeOn();
for(int x = 600; x != 0; x -=50)
{
allledOff();
digitalWrite(Led[0], 0);
digitalWrite(Led[11], 0);
digitalWrite(Led[10], 0);
digitalWrite(Led[9], 0);
delay(x);
digitalWrite(Led[0], 1);
digitalWrite(Led[11], 1);
digitalWrite(Led[10], 1);
digitalWrite(Led[9], 1);
digitalWrite(Led[1], 0);
digitalWrite(Led[12], 0);
digitalWrite(Led[15], 0);
digitalWrite(Led[8], 0);
delay(x);
digitalWrite(Led[1], 1);
digitalWrite(Led[12], 1);
digitalWrite(Led[15], 1);
digitalWrite(Led[8], 1);
digitalWrite(Led[2], 0);
digitalWrite(Led[13], 0);
digitalWrite(Led[14], 0);
digitalWrite(Led[7], 0);
delay(x);
digitalWrite(Led[2], 1);
digitalWrite(Led[13], 1);
digitalWrite(Led[14], 1);
digitalWrite(Led[7], 1);
digitalWrite(Led[3], 0);
digitalWrite(Led[4], 0);
digitalWrite(Led[5], 0);
digitalWrite(Led[6], 0);
delay(x);
}
}
//flicker off
void flicker()
{
allanodeOn();
for(int i = 0; i< 150; i+=5)
{
allledOff();
delay(i+50);
allledOn();
delay(i);
}
}
void allledOn()
{
for(int j = 0; j<16; j++)
{
digitalWrite(Led[j], 0);
}
}
void allledOff()
{
for(int j = 0; j<16; j++)
{
digitalWrite(Led[j], 1);
}
}
void turnallledOn()
{
for(int j = 0; j<12; j++)
{
digitalWrite(Led[j], 0);
delay(15);
}
}
void turnallledOff()
{
for(int j = 0; j<12; j++)
{
digitalWrite(Led[j], 1);
delay(25);
}
}
void allanodeOn()
{
for(int j = 0; j<4; j++)
{
digitalWrite(Anode[j], 1);
}
}
void allanodeOff()
{
for(int j = 0; j<4; j++)
{
digitalWrite(Anode[j], 0);
}
}
void turnallanodeOff()
{
for(int j = 0; j<4; j++)
{
digitalWrite(Anode[j], 0);
delay(10);
}
}
void turnallanodeOn()
{
for(int j = 0; j<4; j++)
{
digitalWrite(Anode[j], 1);
delay(10);
}
}