Ok, so I have written some code that successfully runs 4 LEDs from 4 pins using a sort of charlieplexing (i know i can have more LED's on four pins but there is a grander scheme to my plans which are currently irrelavent). I am pretty new at coding so my knowledge bank is pretty limited with respect to coding different ways to get the same result.
I attached a google sketch I made of an RGB LED tower comprised of 4 leds connected in a way that lets me charlieplex them (so you can get a better understanding of what im doing here). I got the idea from the Asherglick charliecube, and am trying to learn first on coding for one 'spire' (or tower). Each RGB LED sits atop the next, rotated 90degrees and then there are four verticle wires, each one connects one lead from each RGBLED in line (easier to just look at the picture).
For my purposes, I created some code to light up each LED in the tower for each color (R,G,B, and "Off" of course). I provided a sample of the code below. This code works just fine, and i call the functions to lightup the LED and all is well.
Now that ive rambled on and on (trying to give all the info needed!) I will get to my question...
Using the functions below is how I flip each led for each of the basic colors... what im wondering is, is there a way to code this differently so that i could use some sort of statement or something like that to identify the LED's and their color (an array maybe? i dont know) that lets me call the functions more easily and reduce the amount of code? An example of what i do to randomly flash all the LED's with random colors is use a case statement that has one case for EVERY LED/COLOR combination... so thats a bit annoying and i dont know how to reduce the code to do something like that.
Any help would be AWESOME. thanks in advance...marko
int ONEgreen()
{
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, INPUT);
pinMode(12, INPUT);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
}
int THREEred()
{
pinMode(9, INPUT);
pinMode(10, OUTPUT);
pinMode(11, INPUT);
pinMode(12, OUTPUT);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
}
etc......
