I'm working on a project and I want to use two "wheels" of LEDs to create a sort of light show. I've successfully wired it up right and even figured out how to write the code in order to make a few different patterns. You can see a youtube video of what I have so far here:
My problem is that the code I'm using is very bulky. To do the two simple patterns you see in the video I use up 19286 bytes of memory. I still want to add a potentiometer to control the speed and a button, or several buttons, to change between patterns. I'm VERY new to the Arduino and programming so I'm sure I'm doing things the hard way. My problem is all the other charlieplexing code I've seen around the web is way above my head. It just doesn't make sense to me...
Here is part of the code for the patterns you see in the video. I'm not going to include the whole thing because I'm sure you'll get the idea pretty quickly.
int ledPin1 = 7;
int ledPin2 = 6;
int ledPin3 = 5;
int ledPin4 = 4;
int ledPin5 = 3;
int ledPin6 = 2;
int ledPinF = 8;
int ledPinE = 9;
int ledPinD = 10;
int ledPinC = 11;
int ledPinB = 12;
int ledPinA = 13;
void setup() {
}
void loop() {
int a;
for(a = 0;a < 14; a++ )
{
/* Bottom center LED 1*/
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, INPUT);
pinMode(ledPin4, INPUT);
pinMode(ledPin5, INPUT);
pinMode(ledPin6, INPUT);
pinMode(ledPinA, OUTPUT);
pinMode(ledPinB, OUTPUT);
pinMode(ledPinC, INPUT);
pinMode(ledPinD, INPUT);
pinMode(ledPinE, INPUT);
pinMode(ledPinF, INPUT);
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPinA, HIGH);
digitalWrite(ledPinB, LOW);
delay(.5);
/* Top center LED 16*/
pinMode(ledPin1, INPUT);
pinMode(ledPin2, INPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, INPUT);
pinMode(ledPin5, OUTPUT);
pinMode(ledPin6, INPUT);
pinMode(ledPinA, INPUT);
pinMode(ledPinB, INPUT);
pinMode(ledPinC, OUTPUT);
pinMode(ledPinD, INPUT);
pinMode(ledPinE, OUTPUT);
pinMode(ledPinF, INPUT);
digitalWrite(ledPin5, HIGH);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPinE, HIGH);
digitalWrite(ledPinC, LOW);
delay(.5);
/* LED 15*/
pinMode(ledPin1, INPUT);
pinMode(ledPin2, INPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, INPUT);
pinMode(ledPin5, OUTPUT);
pinMode(ledPin6, INPUT);
pinMode(ledPinA, INPUT);
pinMode(ledPinB, INPUT);
pinMode(ledPinC, OUTPUT);
pinMode(ledPinD, INPUT);
pinMode(ledPinE, OUTPUT);
pinMode(ledPinF, INPUT);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin5, LOW);
digitalWrite(ledPinC, HIGH);
digitalWrite(ledPinE, LOW);
delay(.5);
/* LED 17*/
pinMode(ledPin1, INPUT);
pinMode(ledPin2, INPUT);
pinMode(ledPin3, INPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, INPUT);
pinMode(ledPin6, OUTPUT);
pinMode(ledPinA, INPUT);
pinMode(ledPinB, INPUT);
pinMode(ledPinC, INPUT);
pinMode(ledPinD, OUTPUT);
pinMode(ledPinE, INPUT);
pinMode(ledPinF, OUTPUT);
digitalWrite(ledPin4, HIGH);
digitalWrite(ledPin6, LOW);
digitalWrite(ledPinD, HIGH);
digitalWrite(ledPinF, LOW);
delay(.5);
}
Moderator edit: removed scrollathon. AWOL
Now I know I could set all pins to output in the void setup() { } and then set the pins I need to input in each "frame" but I don't know if that'll cut the size of the program down all that much. I tried setting all the pins to input in the void setup() {} so that I could set the pins I needed to output in each "frame" but that didn't work...
I looked at the tutorial for creating libraries. I was thinking about trying to creating a library of 60 functions that I could use to turn on and off each LED as needed but will that actually save me any memory?
There must be a better way to do this. Can anyone make a suggestion?
In the use of the potentiometer. Can you use a variable with delay()?
I tried to use:
int potPin = 2;
int ledDelay;
(then in the void loop)
ledDelay = analogRead(potPin);
(and later in the code)
delay(ledDelay);
I wasn't sure if it worked or not. It seemed to work at times and then didn't. I think my pot may not have been good. I'm not sure of the values of the pot that came with my Arduino experimenters kit. I tried buying a new one at Radio Shack but they didn't have much to choose from. I wound up with a 100K Ohm Linear taper pot at 250VDC, .25W. The pot does nothing now. I didn't realize the 250VDC until this very second when I checked the specs to write this post. I tried to find a 10k ohm or a 4.7k ohm pot that I've seen used in several Arduino circuits but I'm having trouble finding one... Is it my code or my pot? Or maybe both?
As I said I'm very new to all this so please forgive me if some of my questions seem obvious...
Thanks.