vrijdag 28 februari 2020

ATTiny Charlieplex 4 RGB leds

Experimented using 4 charlieplexed RGB leds on a attiny85.
This experiment was done some time ago, and due to the result (watch video below) i hesitated to post it as at that time it was not complete successful.  There are several excellent resource that explain charlieplexing. Therefor i will not try to explain it in detail. In short as leds only light up when the current flows in one direction you can control more leds to a circuit.
I used the code below.

CODE

void setup() {              
  // charlieplex 4 RGB leds 0 1 2 3
  // initialize the digital pin as an output.
}

// the loop routine runs over and over again forever:
void loop() {
 int mydelay = 1000;

  LEDon(3, 2);  // 1R
  delay(mydelay);
  LEDon(3, 0);  // 1G
  delay(mydelay);
  LEDon(3, 1);  // 1B
  delay(mydelay);

  LEDon(0, 1);  // 2R
  delay( mydelay );
  LEDon(0, 3);  // 2G
  delay( mydelay );
  LEDon(0, 2);  // 2B
  delay( mydelay );

  LEDon(1, 0);  // 3R
  delay(mydelay);
  LEDon(1, 2);  // 3G
  delay(mydelay);
  LEDon(1, 3);  // 3B
  delay(mydelay);

  LEDon(2, 3);  // 4R
  delay(mydelay);
  LEDon(2, 1);  // 4G
  delay(mydelay);
  LEDon(2, 0);  // 4B
  delay(mydelay);
}

void LEDon( int gnd, int vin) {
  pinMode(0, INPUT);
  pinMode(1, INPUT);
  pinMode(2, INPUT);
  pinMode(3, INPUT);
//  pinMode(4, INPUT);
//  pinMode(5, INPUT);

  pinMode(vin, OUTPUT);
  pinMode(gnd, OUTPUT);
  digitalWrite(vin, HIGH);
  digitalWrite(gnd, LOW);
}

ENDCODE

When you watch the video you seen some unwanted / unexpected flashes of an RGB led.
This is due to the fact that the attiny85 has an on-board led connected to one of the pins. This interferes with the charlieplexing. To remove this unwanted behavior of the RGB led you need to remove this led.
My first idea was to first make a recording of the correct behaving RGB leds before posting everything on my blog. I did not yet made a video recording after modifying an attiny85. However i later made a custom PCB for charlieplexing. I now decided to post it withe the error due to the led and make later a posting about that PCB where you can see the correct functioning of the RGB leds.



Geen opmerkingen: