Attiny85 Charlieplexed Makerbot Snow Shades

I decided to light up the Snow Shades by MakerBot for a party using an Attiny and some LEDs.

I mocked up LED position and animation:charlieplex14

Then worked out the wiring using the Attiny’s 5 pins.charlieplex14

Modified the model in Blender to allow space for the microchip and LEDs.
cutModel files on Thingiverse.

Using strands of an IDE ribbon cable I connected the LEDs.CWCsPxfXAAAfQmM.jpg large

After connecting the dip socket and batteries I sealed the top with more plastic.IMG_20151218_004224

With Charlieplexed wiring all LEDs can’t be powered on at the same time. The code below pulses the LEDs one after another for different lengths of time to achieve the desired perceived brightness.

 

#include <EEPROM.h>

byte mode = 0;
byte portB=0; byte portMask = 0;
byte dimCount = 0;
byte cBr[14];
int frame = 0;
int frameDuration = 30;
unsigned long lastFrame = 0;
void setup() {                
  mode = EEPROM.read(0);
  mode = mode+1;
  if (mode >= 3){mode = 0;}
  EEPROM.write(0, mode);
}

void loop() {
  while (1==1){
  dimCount++;
  if (dimCount>9){dimCount=0;}
     
      switch (mode) { 
          case 0: //
          frameDuration = 300;
            switch (frame) {
                case 0: //
                  setLED(9,9,9, 9,9,9, 9,9,9,9 ,9,9,9,9); //this sets the led brightness for the duration of one frame
                break;
                case 1: //
                  setLED(0,0,0 ,0,0,0 ,0,0,0,0, 0,0,0,0);
                break;
                case 2: //
                  setLED(9,9,9, 9,9,9, 9,9,9,9 ,9,9,9,9);
                break;
                case 3: //
                  setLED(0,0,0 ,0,0,0 ,0,0,0,0, 0,0,0,0);
                break;
                case 4: //
                  setLED(9,9,9, 9,9,9, 9,9,9,9 ,9,9,9,9);
                break;
                case 5: //
                  setLED(0,0,0, 0,0,0, 9,9,9,9, 9,9,9,9);
                break;
                case 6:
                  setLED(0,0,0, 0,0,0, 9,9,9,0, 0,9,9,9);
                break;
                case 7:
                  setLED(0,0,0, 0,0,0, 9,0,0,0, 0,0,0,9);
                break;
                case 8:
                  setLED(0,0,0, 0,0,0, 0,9,0,0, 0,0,9,0);
                break;
                case 9: //
                  setLED(0,0,0, 0,0,0, 0,0,9,0, 0,9,0,0);
                break;
                case 10: //
                  setLED(0,0,0, 0,0,0, 0,0,0,9, 9,0,0,0);
                break;
                case 11: //
                  setLED(0,0,0, 0,0,0, 0,0,9,0, 0,9,0,0);
                break;
                case 12: //
                  setLED(0,0,0, 0,0,0, 0,9,0,0, 0,0,9,0);
                break;
                case 13: //
                  setLED(0,0,0, 0,0,0, 9,0,0,0, 0,0,0,9);
                break;
                case 14: //
                  setLED(0,0,9, 0,0,9, 0,0,0,0, 0,0,0,0);
                break;
                case 15: //
                  setLED(0,9,0, 0,9,0, 0,0,0,0, 0,0,0,0);
                break;
                case 16: //
                  setLED(9,0,0, 9,0,0, 0,0,0,0, 0,0,0,0);
                break;
                case 17: //
                  setLED(0,0,9, 0,0,9, 0,0,0,0, 0,0,0,0);
                break;
                case 18: //
                  setLED(0,9,0, 0,9,0, 0,0,0,0, 0,0,0,0);
                break;
                case 19: //
                  setLED(9,0,0, 9,0,0, 0,0,0,0, 0,0,0,0);
                break;
                default:
                frame = 0;
                break;
            }
            if (lastFrame+frameDuration<millis()){lastFrame=millis(); frame++;}
          break;
          case 1: //
            switch (frame) {
                case 0: 
                  cBr[0]=0; cBr[1]=3; cBr[2]=7; cBr[3]=7; cBr[4]=3; cBr[5]=0; cBr[6]=0; cBr[7]=3; cBr[8]=7; cBr[9]=9; cBr[10]=9; cBr[11]=7; cBr[12]=3; cBr[13]=0;
                break;
                case 1: //
                  cBr[0]=0; cBr[1]=2; cBr[2]=6; cBr[3]=6; cBr[4]=2; cBr[5]=0; cBr[6]=0; cBr[7]=2; cBr[8]=6; cBr[9]=8; cBr[10]=8; cBr[11]=6; cBr[12]=2; cBr[13]=0;
                break;
                case 2: //
                  cBr[0]=1; cBr[1]=1; cBr[2]=5; cBr[3]=5; cBr[4]=1; cBr[5]=1; cBr[6]=1; cBr[7]=1; cBr[8]=5; cBr[9]=7; cBr[10]=7; cBr[11]=5; cBr[12]=1; cBr[13]=1;
                break;
                case 3:
                  cBr[0]=2; cBr[1]=0; cBr[2]=4; cBr[3]=4; cBr[4]=0; cBr[5]=2; cBr[6]=2; cBr[7]=0; cBr[8]=4; cBr[9]=6; cBr[10]=6; cBr[11]=4; cBr[12]=0; cBr[13]=2;
                break;
                case 4:
                  cBr[0]=3; cBr[1]=0; cBr[2]=3; cBr[3]=3; cBr[4]=0; cBr[5]=3; cBr[6]=3; cBr[7]=0; cBr[8]=3; cBr[9]=5; cBr[10]=5; cBr[11]=3; cBr[12]=0; cBr[13]=3;
                break;
                case 5:
                  cBr[0]=4; cBr[1]=1; cBr[2]=2; cBr[3]=2; cBr[4]=1; cBr[5]=4; cBr[6]=4; cBr[7]=1; cBr[8]=2; cBr[9]=4; cBr[10]=4; cBr[11]=2; cBr[12]=1; cBr[13]=4;
                break;
                case 6:
                  cBr[0]=5; cBr[1]=2; cBr[2]=1; cBr[3]=1; cBr[4]=2; cBr[5]=5; cBr[6]=5; cBr[7]=2; cBr[8]=1; cBr[9]=3; cBr[10]=3; cBr[11]=1; cBr[12]=2; cBr[13]=5;
                break;
                case 7:
                  cBr[0]=6; cBr[1]=3; cBr[2]=0; cBr[3]=0; cBr[4]=3; cBr[5]=6; cBr[6]=6; cBr[7]=3; cBr[8]=0; cBr[9]=2; cBr[10]=2; cBr[11]=0; cBr[12]=3; cBr[13]=6;
                break;
                case 8:
                  cBr[0]=7; cBr[1]=4; cBr[2]=0; cBr[3]=0; cBr[4]=4; cBr[5]=7; cBr[6]=7; cBr[7]=4; cBr[8]=0; cBr[9]=1; cBr[10]=1; cBr[11]=0; cBr[12]=4; cBr[13]=7;
                break;
                case 9:
                  cBr[0]=8; cBr[1]=5; cBr[2]=1; cBr[3]=1; cBr[4]=5; cBr[5]=8; cBr[6]=8; cBr[7]=5; cBr[8]=1; cBr[9]=0; cBr[10]=0; cBr[11]=1; cBr[12]=5; cBr[13]=8;
                break;
                case 10:
                  cBr[0]=9; cBr[1]=6; cBr[2]=2; cBr[3]=2; cBr[4]=6; cBr[5]=9; cBr[6]=9; cBr[7]=6; cBr[8]=2; cBr[9]=0; cBr[10]=0; cBr[11]=2; cBr[12]=6; cBr[13]=9;
                break;
                case 11:
                  cBr[0]=9; cBr[1]=7; cBr[2]=3; cBr[3]=3; cBr[4]=7; cBr[5]=9; cBr[6]=9; cBr[7]=7; cBr[8]=3; cBr[9]=1; cBr[10]=1; cBr[11]=3; cBr[12]=7; cBr[13]=9;
                break;
                case 12:
                  cBr[0]=8; cBr[1]=8; cBr[2]=4; cBr[3]=4; cBr[4]=8; cBr[5]=8; cBr[6]=8; cBr[7]=8; cBr[8]=4; cBr[9]=2; cBr[10]=2; cBr[11]=4; cBr[12]=8; cBr[13]=8;
                break;
                case 13:
                  cBr[0]=7; cBr[1]=9; cBr[2]=5; cBr[3]=5; cBr[4]=9; cBr[5]=7; cBr[6]=7; cBr[7]=9; cBr[8]=5; cBr[9]=3; cBr[10]=3; cBr[11]=5; cBr[12]=9; cBr[13]=7;
                break;
                case 14:
                  cBr[0]=6; cBr[1]=9; cBr[2]=6; cBr[3]=6; cBr[4]=9; cBr[5]=6; cBr[6]=6; cBr[7]=9; cBr[8]=6; cBr[9]=4; cBr[10]=4; cBr[11]=6; cBr[12]=9; cBr[13]=6;
                break;
                case 15:
                  cBr[0]=5; cBr[1]=8; cBr[2]=7; cBr[3]=7; cBr[4]=8; cBr[5]=5; cBr[6]=5; cBr[7]=8; cBr[8]=7; cBr[9]=5; cBr[10]=5; cBr[11]=7; cBr[12]=8; cBr[13]=5;
                break;
                case 16:
                  cBr[0]=4; cBr[1]=7; cBr[2]=8; cBr[3]=8; cBr[4]=7; cBr[5]=4; cBr[6]=4; cBr[7]=7; cBr[8]=8; cBr[9]=6; cBr[10]=6; cBr[11]=8; cBr[12]=7; cBr[13]=4;
                break;
                case 17:
                  cBr[0]=3; cBr[1]=6; cBr[2]=9; cBr[3]=9; cBr[4]=6; cBr[5]=3; cBr[6]=3; cBr[7]=6; cBr[8]=9; cBr[9]=7; cBr[10]=7; cBr[11]=9; cBr[12]=6; cBr[13]=3;
                break;
                case 18:
                  cBr[0]=2; cBr[1]=5; cBr[2]=9; cBr[3]=9; cBr[4]=5; cBr[5]=2; cBr[6]=2; cBr[7]=5; cBr[8]=9; cBr[9]=8; cBr[10]=8; cBr[11]=9; cBr[12]=5; cBr[13]=2;
                break;
                case 19:
                  cBr[0]=1; cBr[1]=4; cBr[2]=8; cBr[3]=8; cBr[4]=4; cBr[5]=1; cBr[6]=1; cBr[7]=4; cBr[8]=8; cBr[9]=9; cBr[10]=9; cBr[11]=8; cBr[12]=4; cBr[13]=1;
                break;
                default:
                frame = 19;
                break;
            }
            if (lastFrame+frameDuration<millis()){lastFrame=millis(); frame--;}
          break;
          case 2: //
            switch (frame) {
                case 0: //
                  setLED(9,3,0, 4,0,8, 9,5,9,2, 6,6,3,1);
                break;
                case 1: //
                  setLED(8,2,1, 3,1,7, 8,6,8,3, 7,5,4,0);
                break;
                case 2: //
                  setLED(7,1,2, 2,2,6, 7,7,7,4, 8,4,5,0);
                break;
                case 3: //
                  setLED(6,0,3 ,1,3,5 ,6,8,6,5, 9,3,6,1);
                break;
                case 4: //
                  setLED(5,0,4 ,0,4,4 ,5,9,5,6, 9,2,7,2);
                break;
                case 5: //
                  setLED(4,1,5 ,0,5,3 ,4,9,4,7, 8,1,8,3);
                break;
                case 6:
                  setLED(3,2,6, 1,6,2, 3,8,3,8, 7,0,9,4);
                break;
                case 7:
                  setLED(2,3,7, 2,7,1, 2,7,2,9, 6,0,9,5);
                break;
                case 8:
                  setLED(1,4,8, 3,8,0, 1,6,1,9, 5,1,8,6);
                break;
                case 9: //
                  setLED(0,5,9, 4,9,0, 0,5,0,8, 4,2,7,7);
                break;
                case 10: //
                  setLED(0,6,9, 5,9,1, 0,4,0,7, 3,3,6,8);
                break;
                case 11: //
                  setLED(1,7,8, 6,8,2, 1,3,1,6, 2,4,5,9);
                break;
                case 12: //
                  setLED(2,8,7, 7,7,3, 2,2,2,5, 1,5,4,9);
                break;
                case 13: //
                  setLED(3,9,6, 8,6,4, 3,1,3,4, 0,6,3,8);
                break;
                case 14: //
                  setLED(4,9,5, 9,5,5, 4,0,4,3, 0,7,2,7);
                break;
                case 15: //
                  setLED(5,8,4, 9,4,6, 5,0,5,2, 1,8,1,6);
                break;
                case 16: //
                  setLED(6,7,3, 8,3,7, 6,1,6,1, 2,9,0,5);
                break;
                case 17: //
                  setLED(7,6,2, 7,2,8, 7,2,7,0, 3,9,0,4);
                break;
                case 18: //
                  setLED(8,5,1, 6,1,9, 8,3,8,0, 4,8,1,3);
                break;
                case 19: //
                  setLED(9,4,0, 5,0,9, 9,4,9,1, 5,7,2,2);
                break;
                default:
                frame = 0;
                break;
            }
            if (lastFrame+frameDuration<millis()){lastFrame=millis(); frame++;}
          break;
          
          case 3:
          
          break;
          case 4:
            
          break;
      }
      pull_port();  
  }
}

void pull_port (){
//  byte portOn = B00000000; byte mortMode = B00000000;
  if (cBr[0]>dimCount){PORTB = B00010000; DDRB = B00010100;}else {dimAll();}
  delayMicroseconds(1);
  if (cBr[1]>dimCount){PORTB = B00000100; DDRB = B00010100;}else {dimAll();}
  delayMicroseconds(1);
  if (cBr[2]>dimCount){PORTB = B00000100; DDRB = B00001100;}else {dimAll();}
  delayMicroseconds(1);
  if (cBr[3]>dimCount){PORTB = B00001000; DDRB = B00001100;}else {dimAll();}
  delayMicroseconds(1);
  if (cBr[4]>dimCount){PORTB = B00000100; DDRB = B00000101;}else {dimAll();}  
  delayMicroseconds(1);
  if (cBr[5]>dimCount){PORTB = B00000001; DDRB = B00000101;}else {dimAll();}
  delayMicroseconds(1);
  if (cBr[6]>dimCount){PORTB = B00000010; DDRB = B00001010;}else {dimAll();}
  delayMicroseconds(1);
  if (cBr[7]>dimCount){PORTB = B00001000; DDRB = B00001010;}else {dimAll();}
  delayMicroseconds(1);
  if (cBr[8]>dimCount){PORTB = B00010000; DDRB = B00011000;}else {dimAll();}
  delayMicroseconds(1);
  if (cBr[9]>dimCount){PORTB = B00001000; DDRB = B00011000;}else {dimAll();}
  delayMicroseconds(1);
  if (cBr[10]>dimCount){PORTB = B00000001; DDRB = B00000011;}else {dimAll();}
  delayMicroseconds(1);
  if (cBr[11]>dimCount){PORTB = B00000010; DDRB = B00000011;}else {dimAll();}
  delayMicroseconds(1);
  if (cBr[12]>dimCount){PORTB = B00000100; DDRB = B00000110;}else {dimAll();}
  delayMicroseconds(1);
  if (cBr[13]>dimCount){PORTB = B00000010; DDRB = B00000110;}else {dimAll();}
  delayMicroseconds(1);
  dimAll(); // to make sure the last led has the same brightness
}
void setLED(byte L1, byte L2, byte L3, byte L4, byte L5, byte L6, byte L7, byte L8, byte L9, byte L10, byte L11, byte L12, byte L13, byte L14 ){
  cBr[0]=L1; cBr[1]=L2; cBr[2]=L3; cBr[3]=L4; cBr[4]=L5; cBr[5]=L6; cBr[6]=L7; cBr[7]=L8; cBr[8]=L9; cBr[9]=L10; cBr[10]=L11; cBr[11]=L12; cBr[12]=L13; cBr[13]=L14;
}
void dimAll(){
   PORTB = B00000000; DDRB = B00000000; // dim all 
}

Merry Christmas!

IMG_20151218_014039

Leave a Reply

Your email address will not be published. Required fields are marked *