Blogroll

Powered by Blogger.

Sunday, 12 October 2014

Arduino Program to Turn on Diagonal LEDs of 3*3*3 LED Cube (Part 10 of 10)

by realfinetime  |  in LED Cube at  02:35

<<<<  Read Previous Part (Part 9)

Arduino program to turn on diagonal LEDs only (Part 3 of 3)

This will give the expected output as shown below.

Arduino program to turn on diagonal LEDs only. Upload this program to your arduino board.

int neg1 = 13;  //"neg1" is connected to the 13th digital pin of arduino
int neg2 = 12;  //"neg2" is connected to the 12th digital pin of arduino
int neg3 = 11;  //"neg3" is connected to the 11th digital pin of arduino
int neg4 = 10;  //"neg4" is connected to the 10th digital pin of arduino
int neg5 = 9;   //"neg5" is connected to the 9th digital pin of arduino
int neg6 = 8;   //"neg6" is connected to the 8th digital pin of arduino
int neg7 = 7;   //"neg7" is connected to the 7th digital pin of arduino
int neg8 = 6;   //"neg8" is connected to the 6th digital pin of arduino
int neg9 = 5;   //"neg9" is connected to the 5th digital pin of arduino

int pos1 = 4;   //"pos1" is connected to the 4th digital pin of arduino
int pos2 = 3;   //"pos2" is connected to the 3rd digital pin of arduino
int pos3 = 2;   //"pos3" is connected to the 2nd digital pin of arduino
int j=0;
// the setup routine runs once when you press reset: void setup() {   // initialize the digital pin as an output.   pinMode(neg1, OUTPUT);   pinMode(neg2, OUTPUT);   pinMode(neg3, OUTPUT);   pinMode(neg4, OUTPUT);   pinMode(neg5, OUTPUT);   pinMode(neg6, OUTPUT);   pinMode(neg7, OUTPUT);   pinMode(neg8, OUTPUT);   pinMode(neg9, OUTPUT);      pinMode(pos1, OUTPUT);   pinMode(pos2, OUTPUT);   pinMode(pos3, OUTPUT); } // the loop routine runs over and over again forever: void loop() {     // Will turn on LED connected to "pos1" and "neg1"   for(j=0;j<20;j++)   {     digitalWrite(pos1, HIGH);     digitalWrite(pos2, LOW);     digitalWrite(pos3, LOW);        digitalWrite(neg1, LOW);     digitalWrite(neg2, HIGH);     digitalWrite(neg3, HIGH);     digitalWrite(neg4, HIGH);     digitalWrite(neg5, HIGH);     digitalWrite(neg6, HIGH);     digitalWrite(neg7, HIGH);     digitalWrite(neg8, HIGH);     digitalWrite(neg9, HIGH);   }      //Turn off all LEDs   digitalWrite(pos1, LOW);   digitalWrite(pos2, LOW);   digitalWrite(pos3, LOW);      digitalWrite(neg1, HIGH);   digitalWrite(neg2, HIGH);   digitalWrite(neg3, HIGH);   digitalWrite(neg4, HIGH);   digitalWrite(neg5, HIGH);   digitalWrite(neg6, HIGH);   digitalWrite(neg7, HIGH);   digitalWrite(neg8, HIGH);   digitalWrite(neg9, HIGH);        // Will turn on LED connected to "pos2" and "neg5"   for(j=0;j<20;j++)   {         digitalWrite(pos1, LOW);     digitalWrite(pos2, HIGH);     digitalWrite(pos3, LOW);        digitalWrite(neg1, HIGH);     digitalWrite(neg2, HIGH);     digitalWrite(neg3, HIGH);     digitalWrite(neg4, HIGH);     digitalWrite(neg5, LOW);     digitalWrite(neg6, HIGH);     digitalWrite(neg7, HIGH);     digitalWrite(neg8, HIGH);     digitalWrite(neg9, HIGH);   }   // Turn off all LEDs   digitalWrite(pos1, LOW);   digitalWrite(pos2, LOW);   digitalWrite(pos3, LOW);      digitalWrite(neg1, HIGH);   digitalWrite(neg2, HIGH);   digitalWrite(neg3, HIGH);   digitalWrite(neg4, HIGH);   digitalWrite(neg5, HIGH);   digitalWrite(neg6, HIGH);   digitalWrite(neg7, HIGH);   digitalWrite(neg8, HIGH);   digitalWrite(neg9, HIGH);      // Will turn on LED connected to "pos3" and "neg9"   for(j=0;j<20;j++)   {          digitalWrite(pos1, LOW);     digitalWrite(pos2, LOW);     digitalWrite(pos3, HIGH);        digitalWrite(neg1, HIGH);     digitalWrite(neg2, HIGH);     digitalWrite(neg3, HIGH);     digitalWrite(neg4, HIGH);     digitalWrite(neg5, HIGH);     digitalWrite(neg6, HIGH);     digitalWrite(neg7, HIGH);     digitalWrite(neg8, HIGH);     digitalWrite(neg9, LOW);   }        // Turn off all LEDs   digitalWrite(pos1, LOW);   digitalWrite(pos2, LOW);   digitalWrite(pos3, LOW);      digitalWrite(neg1, HIGH);   digitalWrite(neg2, HIGH);   digitalWrite(neg3, HIGH);   digitalWrite(neg4, HIGH);   digitalWrite(neg5, HIGH);   digitalWrite(neg6, HIGH);   digitalWrite(neg7, HIGH);   digitalWrite(neg8, HIGH);   digitalWrite(neg9, HIGH); }

          If uploading is successful, diagonal LEDs will turn on and all other LEDs will turn off. Similarly, we can turn on any set of diagonal LEDs.

Next : Video Demonstration of 3*3*3 LED Cube >>>>

0 comments:

IMPORTANT NOTICE

All the circuits, published in this blog is only after testing and getting proper results in my private lab. When you try these circuits, you should check the supply voltage, polarity of components, presence of childrens nearby and shorts in the circuits. This website will not be responsible for any harm happened to you or your components caused by your carelessness.

For More Electronic Tips

Blog Archive

Proudly Powered by Blogger.