Last active
December 16, 2015 04:29
-
-
Save amiel/5377064 to your computer and use it in GitHub Desktop.
Digispark Charlieplex http://digistump.com/products/13 using this charlieplexing library http://playground.arduino.cc/code/charlieplex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Charlieplex.h> | |
#define NUMBER_OF_PINS 5 | |
byte pins[] = {0,1,2,3,4}; | |
Charlieplex charlieplex = Charlieplex(pins,NUMBER_OF_PINS); | |
typedef bool grid[6][5]; | |
int h = 5; | |
int w = 4; | |
charliePin leds[6][5] = { | |
{{0, 1}, {0, 2}, {0, 3}, {0, 4}}, | |
{{1, 0}, {1, 2}, {1, 3}, {1, 4}}, | |
{{2, 0}, {2, 1}, {2, 3}, {2, 4}}, | |
{{3, 0}, {3, 1}, {3, 2}, {3, 4}}, | |
{{4, 0}, {4, 1}, {4, 2}, {4, 3}} | |
}; | |
grid six = { | |
{LOW, HIGH, HIGH, HIGH}, | |
{LOW, LOW, LOW, HIGH}, | |
{LOW, HIGH, HIGH, HIGH}, | |
{LOW, HIGH, LOW, HIGH}, | |
{LOW, HIGH, HIGH, HIGH} | |
}; | |
grid four = { | |
{LOW, HIGH, LOW, HIGH}, | |
{LOW, HIGH, LOW, HIGH}, | |
{LOW, HIGH, HIGH, HIGH}, | |
{LOW, HIGH, LOW, LOW}, | |
{LOW, HIGH, LOW, LOW} | |
}; | |
void setup() { | |
} | |
void loop() { | |
unsigned long t = millis(); | |
int phase = t % 5; | |
grid* state; | |
if (t % 2000 < 1000) { | |
state = &six; | |
} else { | |
state = &four; | |
} | |
charlieplex.charlieWrite(leds[phase][0], (*state)[phase][0]); | |
charlieplex.charlieWrite(leds[phase][1], (*state)[phase][1]); | |
charlieplex.charlieWrite(leds[phase][2], (*state)[phase][2]); | |
charlieplex.charlieWrite(leds[phase][3], (*state)[phase][3]); | |
delay(1); | |
charlieplex.clear(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
|| | |
|| @author Alexander Brevig | |
|| @version 1.0 | |
|| | |
*/ | |
#include "Charlieplex.h" | |
Charlieplex::Charlieplex(byte* userPins,byte numberOfUserPins){ | |
pins = userPins; | |
numberOfPins = numberOfUserPins; | |
clear(); | |
} | |
void Charlieplex::charlieWrite(charliePin pin, bool state){ | |
if(state){ | |
setVcc(pin.vcc); | |
setGnd(pin.gnd); | |
}else{ | |
pinMode(pin.vcc,INPUT); | |
} | |
} | |
//set a pin HIGH | |
void Charlieplex::setVcc(byte pin){ | |
pinMode( pins[pin] , OUTPUT ); | |
digitalWrite( pins[pin] , HIGH ); | |
} | |
//set a pin LOW | |
void Charlieplex::setGnd(byte pin){ | |
pinMode( pins[pin] , OUTPUT ); | |
digitalWrite( pins[pin] , LOW ); | |
} | |
//set all as input | |
void Charlieplex::clear(){ | |
for (byte i=0; i<numberOfPins; i++){ | |
pinMode( pins[i] , INPUT); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment