Patrick Prescott
Published © GPL3+

Charlie Chaser

A simple demonstration of charlieplexing: 12 LEDs are individually lit over 4 wires.

BeginnerShowcase (no instructions)7,085
Charlie Chaser

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
5 mm LED: Green
5 mm LED: Green
×12
Resistor 100 ohm
Resistor 100 ohm
×4
Mini Breadboard
×1
Jumper Wires
This part is a collection of wires. Many wires were used.
×1

Software apps and online services

Codebender
My primary IDE

Hand tools and fabrication machines

Tweezers
Those tiny jumper wires don't place themselves.

Story

Read more

Schematics

Breadboard Layout

This show the details of how the breadboard is laid out.

Schematic

Code

Untitled file

Arduino
int ledPins[] = {5, 6, 10, 11};
int pinCount = 4;

class charlie{
	int pin1,pin2;
	
	public:
	charlie(int firstPin, int secondPin){
		pin1 = firstPin;
		pin2 = secondPin;
	}
	
	void flash(int duration, bool forward){
		setupPins();
		if(forward){
	    	digitalWrite(pin1, LOW);
	    	digitalWrite(pin2, HIGH);
		} else {
	    	digitalWrite(pin1, HIGH);
	    	digitalWrite(pin2, LOW);
		}
    	delay(duration);
	}
	
	void flash(int duration, bool forward, int intensity){
		setupPins();
		if(forward){
	    	analogWrite(pin1, intensity);
	    	digitalWrite(pin2, HIGH);
		} else {
	    	digitalWrite(pin1, HIGH);
	    	analogWrite(pin2, intensity);
		}
    	delay(duration);
	}
	
	private:
	
	void setupPins(){
		for (int thisPin = 0; thisPin < pinCount; thisPin++) {
	    	if(ledPins[thisPin] != pin1 and ledPins[thisPin] != pin2){
	    		pinMode(ledPins[thisPin], INPUT);
	    	}
		};
		
		pinMode(pin1, OUTPUT);
    	pinMode(pin2, OUTPUT);
	}
};

charlie C1(6,10);
charlie C2(11,10);
charlie C3(11,6);
charlie C4(11,5);
charlie C5(10,5);
charlie C6(6,5);

charlie Charlies[] = {C1,C2,C3,C4,C5,C6};

void setup()
{
	
}

void loop()
{
	int duration = 40;
	int durationStep = 3;
	int intensityStep = 3;
	
	for(int intensity = 240; intensity > 0; intensity += 0){
		for (int thisCharlie = 0; thisCharlie < 6; thisCharlie++) {
	    	Charlies[thisCharlie].flash(duration, true, intensity);
	    	intensity -= intensityStep;
		};
		for (int thisCharlie = 5; thisCharlie >= 0; thisCharlie--) {
	    	Charlies[thisCharlie].flash(duration, false, intensity);
	    	intensity -= intensityStep;
		};
		duration -= durationStep;
	}
	
	for (int thisCharlie = 0; thisCharlie < 6; thisCharlie++) {
	    	Charlies[thisCharlie].flash(duration, true);
		};
		for (int thisCharlie = 5; thisCharlie >= 0; thisCharlie--) {
	    	Charlies[thisCharlie].flash(duration, false);
		};
	
	for(int intensity = 0; intensity < 240; intensity += 0){
		for (int thisCharlie = 0; thisCharlie < 6; thisCharlie++) {
	    	Charlies[thisCharlie].flash(duration, true, intensity);
	    	intensity += intensityStep;
		};
		for (int thisCharlie = 5; thisCharlie >= 0; thisCharlie--) {
	    	Charlies[thisCharlie].flash(duration, false, intensity);
	    	intensity += intensityStep;
		};
		duration += durationStep;
	}
}

Charlie Chaser

This code creates objects for each pair of LEDs connected in parallel, but opposite polarity. The "flash" methods control how the lights are turned on. The main loop increases and then decreases speed and intensity of the LEDs chasing around the perimeter of the breadboard.

Credits

Patrick Prescott

Patrick Prescott

3 projects • 22 followers
I love all sorts of making. Electronics is probably my favorite, but carpentry is a close second.

Comments