Hello,
I only found one topic about this, but it's done with 20 ports.
What I want to do:
•Create a charlieplexed row of 12 LED's driven by a AtTiny85 chip (PWM).
What I have managed yet:
•Create a working charlieplexed row with some code found on the web
•create a working sketch with 4 (software)PWM pins.
What are my problems:
•Combine chalieplex and the 4 pins S-PWM
•Create an 'animation' of a shooting star/snowdrop with tail and a delayed end drop.
(like this video)
This are the codes I found:
The falling animation (No Charlieplex)
void setup() {
for (uint8_t pin=0; pin<5; ++pin) {
pinMode(pin, OUTPUT);
}
}
uint8_t brightness(const int8_t led, const int8_t pos) {
switch (abs(led-pos)) {
case 0: return 32;
case 1: return 16;
case 2: return 6;
case 3: return 2;
default: return 1;
}
}
void pulse_width_modulation(const uint8_t pos) {
for(uint8_t times=0; times<100; ++times) {
for (uint8_t pass=0; pass<32; ++pass) {
for (int8_t led=0; led<20; ++led) {
digitalWrite(led, (brightness(led, pos) > pass));
}
}
}
}
void loop() {
static uint8_t pos=0;
while(pos<12) {
pulse_width_modulation(pos);
++pos;
}
delay(1000);
pos=0;
}
A code with PWM (no SPWM) Lighting one after an other
/*
* Arrays containing the pin numbers used in
* each charlieplexed matrix. In this case, both
* matrices are the same size, and this code will
* not work properly if this is not the case.
*/
int charlie1[4] = { 1, 2, 3, 4};
int numPins = sizeof(charlie1)/sizeof(int);
int dropLed = 0;
void setup() {
// Set all pins to output-
for(int i = 0; i < numPins; i++) {
pinMode(charlie1[i], OUTPUT);
pinMode(dropLed, OUTPUT);
}
}
void fadeSingle(int pinArray[],
int source, int sink,
int dir, int del) {
/*
* Fade a single charlieplexed LED in or out.
* pinArray[] = Array of PWM pin numbers
* source = Index of the source pin in the array
* sink = Index of the sink pin in the array
* dir = Direction of fade. 0 = Down; 1 = Up.
* del = Fade delay(microseconds)
*/
// Set pin modes
pinMode(pinArray[source], OUTPUT);
pinMode(pinArray[sink], OUTPUT);
// Set the sink pin to low straight away
digitalWrite(pinArray[sink], LOW);
// Find any other pins in the array, and disable them
// by setting them to INPUT
for(int pin = 0; pin < numPins; pin++) {
if(pin != source && pin != sink) {
pinMode(pinArray[pin], INPUT);
}
}
// Now fade the source pin in or out
if(dir > 0) {
for(int fadeVal = 0; fadeVal < 256; fadeVal++) {
analogWrite(pinArray[source], fadeVal);
delayMicroseconds(del);
}
} else {
for(int fadeVal = 255; fadeVal >= 0; fadeVal--) {
analogWrite(pinArray[source], fadeVal);
delayMicroseconds(del);
}
}
}
void loop() {
// Fade through all permutation
allPermsFade();
//for (int i=0; i>255; i--);
// analogWrite (dropLed, 255);
// delay(1000);
// // fade out from max to min in increments of 5 points:
// for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
// // sets the value (range from 0 to 255):
// analogWrite(dropLed, fadeValue);
// // wait for 30 milliseconds to see the dimming effect
// delay(30);
// }
// delay(2000);
}
void allPermsFade() {
/*
* Loop through all permutations, fading
* each in then out with a 2ms delay between
* increments
*/
for(int i = 0; i < numPins; i++) {
for(int j = 0; j < numPins; j++) {
if(i == j) {
continue;
}
fadeSingle(charlie1, i, j, 1, 500);
fadeSingle(charlie1, i, j, 0, 500);
}
}
}