Charlieplexing Fun

Just got done with some VERY basic charlieplexing... In this post, I will be assuming that you know what charlieplexing is / how to charlieplex. This uses 3 pins from the Arduino. 12 is the "top", or left, 13 is the center, or "middle", and 11 is the "bottom", or right.

Also, In the second and third parts, there are buttons to turn on each led.

Also, on the button ones, it lags for a little bit... Sometimes you have to hold the button for a little while... Can you help me stop the lag?

Cycle

int top = 12;
int middle = 13;
int bottom = 11;

int wait = 500;

void setup(){
}

void loop(){
 pinMode(top, OUTPUT);
 pinMode(middle, OUTPUT);
 pinMode(bottom, INPUT);
 
 digitalWrite(middle, HIGH);
 digitalWrite(top, LOW);
 
 delay(wait);

 pinMode(top, OUTPUT);
 pinMode(middle, OUTPUT);
 pinMode(bottom, INPUT);
 
 digitalWrite(top, HIGH);
 digitalWrite(middle, LOW);
 
 delay(wait);

 pinMode(middle, OUTPUT);
 pinMode(bottom, OUTPUT);
 pinMode(top, INPUT);
 
 digitalWrite(bottom, HIGH);
 digitalWrite(middle, LOW);
 
 delay(wait);

 pinMode(middle, OUTPUT);
 pinMode(bottom, OUTPUT);
 pinMode(top, INPUT);
 
 digitalWrite(middle, HIGH);
 digitalWrite(bottom, LOW);
 
 delay(wait);
}

Buttons

int top = 12;
int middle = 13;
int bottom = 11;

int button1 = 10;
int button2 = 9;
int button3 = 8;
int button4 = 7;

int button1State;
int button2State;
int button3State;
int button4State;

int wait = 500;

void setup(){
 pinMode(button1, INPUT); 
 pinMode(button2, INPUT); 
 pinMode(button3, INPUT); 
 pinMode(button4, INPUT); 
 
 digitalWrite(button1, HIGH);
 digitalWrite(button2, HIGH);
 digitalWrite(button3, HIGH);
 digitalWrite(button4, HIGH);
}

void loop(){ 
 button1State = digitalRead(button1); 
 button2State = digitalRead(button2); 
 button3State = digitalRead(button3); 
 button4State = digitalRead(button4); 
  
 if(button1State == LOW){   
  pinMode(top, OUTPUT);
  pinMode(middle, OUTPUT);
  pinMode(bottom, INPUT);
 
  digitalWrite(middle, HIGH);
  digitalWrite(top, LOW);
 }

 if(button2State == LOW){   
  pinMode(top, OUTPUT);
  pinMode(middle, OUTPUT);
  pinMode(bottom, INPUT);
 
  digitalWrite(top, HIGH);
  digitalWrite(middle, LOW);
 } 

 if(button3State == LOW){
  pinMode(middle, OUTPUT);
  pinMode(bottom, OUTPUT);
  pinMode(top, INPUT);
 
  digitalWrite(bottom, HIGH);
  digitalWrite(middle, LOW);
 }

 if(button4State == LOW){
  pinMode(middle, OUTPUT);
  pinMode(bottom, OUTPUT);
  pinMode(top, INPUT);
 
  digitalWrite(middle, HIGH);
  digitalWrite(bottom, LOW);
 } 

 delay(wait);
}

Buttons With Off When No Buttons Are Pressed

int top = 12;
int middle = 13;
int bottom = 11;

int button1 = 10;
int button2 = 9;
int button3 = 8;
int button4 = 7;

int button1State;
int button2State;
int button3State;
int button4State;

int wait = 500;

void setup(){
 pinMode(button1, INPUT); 
 pinMode(button2, INPUT); 
 pinMode(button3, INPUT); 
 pinMode(button4, INPUT); 
 
 digitalWrite(button1, HIGH);
 digitalWrite(button2, HIGH);
 digitalWrite(button3, HIGH);
 digitalWrite(button4, HIGH);
}

void loop(){ 
 button1State = digitalRead(button1); 
 button2State = digitalRead(button2); 
 button3State = digitalRead(button3); 
 button4State = digitalRead(button4); 
  
 if(button1State == LOW){   
  pinMode(top, OUTPUT);
  pinMode(middle, OUTPUT);
  pinMode(bottom, INPUT);
 
  digitalWrite(middle, HIGH);
  digitalWrite(top, LOW);
 }

 if(button2State == LOW){   
  pinMode(top, OUTPUT);
  pinMode(middle, OUTPUT);
  pinMode(bottom, INPUT);
 
  digitalWrite(top, HIGH);
  digitalWrite(middle, LOW);
 } 

 if(button3State == LOW){
  pinMode(middle, OUTPUT);
  pinMode(bottom, OUTPUT);
  pinMode(top, INPUT);
 
  digitalWrite(bottom, HIGH);
  digitalWrite(middle, LOW);
 }

 if(button4State == LOW){
  pinMode(middle, OUTPUT);
  pinMode(bottom, OUTPUT);
  pinMode(top, INPUT);
 
  digitalWrite(middle, HIGH);
  digitalWrite(bottom, LOW);
 } 
 
 else if(button1State == HIGH && button2State == HIGH && button3State == HIGH && button4State == HIGH){
  pinMode(top, INPUT);
  pinMode(middle, INPUT);
  pinMode(bottom, INPUT);
 }  

 delay(wait);
}

delay is your source of button lag, whip up a little "without delay" timer comparison function and I bet it goes away

oldtime = 0
wait time = 100

if current time > old time do stuff and update old time

^^^^^
Huh? All I know is that I think it has to wait to be done witht he previous blink to read again. Would the millis() blink fix that?

Well, i do see a delay(500); wich is 1/2 of a second, that could get you some lag!! are you taking about a 1/2 second lag?

BTW i this this post should be in software question not exhibition
my 2 cents.
Pat Gadget

I am showing off what I did... I am just asking for ways to make it better...

As for the delay, that is so that the led stays on for 1/2 second.

and it halts the cpu for a half second = button lag

go look at the blink without delay example to have no lag and timing