Author Topic: Charlieplex code  (Read 2166 times)

gohops

  • Newbie
  • *
  • Posts: 1
Charlieplex code
« on: March 16, 2013, 02:49:00 pm »

Here's a function I wrote for the Charlieplex board. As a alternative to the LEDon function example. In my interface I used used x,y coordinates, instead of pin numbers. I find this easier to use.   


Code: [Select]
void blink(int x, int y) {
  pinMode(0, INPUT);
  pinMode(1, INPUT);
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(4, INPUT);
  delay(1);
 
  int vin=y;
  int gnd=x;
  if (x>=y) gnd++;
  digitalWrite(vin, HIGH);
  digitalWrite(gnd, LOW);
  pinMode(vin, OUTPUT);   
  pinMode(gnd, OUTPUT);
  delay(1);
 }


Here is an example of using this code:


Code: [Select]
void blink_e() {
  blink (3,4);
  blink (2,4);
  blink (1,4);
  blink (0,4);
  blink (0,3);
  blink (0,2);
  blink (1,2);
  blink (2,2);
  blink (0,1);
  blink (0,0);
  blink (1,0);
  blink (2,0);
  blink (3,0);
}
void loop() {
  blink_e();
}