projekte:berlinbadge_rev1

BerlinBadge rev1

Label Qty Value Footprint Description
BT1 1 Connector JST PH 2.00mm 2-Pins Horizontal
C1, C4, C7, C9, C10, C13, C14 7 100nF 0805 C
C2, C3, C5, C6, C8, C11 6 2.2uF 0805 C
C12 1 4.7uF 0805 C
D1, D2, D3, D4, D5, D6, D7, D8 8 WS2812B 5050 LED P3.2mm
D9 1 ca. 3V 10mA LED (Yellow) 0805 LED
J1 1 Connector 2×3 Odd_Even Pinheader 2.54mm Vertical NOT MOUNTED
J2 1 USB A USB A Stewart SS52100-001 Horizontal
JP1 1 - nothing to mount Solder to match the maximum voltage of the battery
P1 1 - nothing to mount AVR ISProgrammer, MaxConnect Link
R1, R3 2 10K 0805 R
R2 1 1K 0805 R series resistor for D9, match current!
R4, R5, R6, R7, R8, R9 OR 0805 R just for layouting reasons
SW1 1 Switch SPDT_PCM12 Example: Amazon Link
U1 1 ATTiny85-20SU SOIJ-8_5.3×5.3mm P1.27mm Reichelt ATTINY85-20SU
U2 1 MAX1811 SOIC-8_3.9×4.9mm P1.27

This is the arduino code running on rev1. You need to install the neopixel lib and compile for Attiny85 with internal 16MHz!

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
 #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
 
 
#define LED_PIN     PB1
#define LED_COUNT  8
#define BRIGHTNESS 255
 
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_RGB + NEO_KHZ800);
 
#define PERCENT_SPAWN 6
 
struct C{
  byte red;
  byte green;
  byte blue;
};
 
#define NUM_COLORS 16
C colors[] = {
  {0,0,255},
  {0,255,0},
  {255,0,0},
  {0,255,0},
  {60,240,0},
  {255,255,255},
  {10,40,128},
  {70,140,10},
  {140,70,10},
  {12,96,190},
  {200,10,80},
  {200,80,10},
  {80,10,190},
  {0,0,255},
};
 
C leds[LED_COUNT];
C ledsIst[LED_COUNT];
int state[LED_COUNT];
 
void setup() {
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
  clock_prescale_set(clock_div_1);
#endif
 
  strip.begin();
  strip.show();
  strip.setBrightness(BRIGHTNESS);
 
  for(int i=0; i<strip.numPixels(); i++) {
    leds[i].red = 0;
    leds[i].blue = 0;
    leds[i].green = 0;
  }
}
 
void clearLED(int i){
  leds[i].red = 0;
  leds[i].blue = 0;
  leds[i].green = 0;
}
 
bool isOut(int i){
  return leds[i].red == 0 && leds[i].blue == 0 && leds[i].green == 0;
}
 
void setLED(int i, C c){
  leds[i].red = c.red;
  leds[i].blue = c.blue;
  leds[i].green = c.green;
  state[i] = 1;
}
 
void dimLED(int i){
  if(state[i] == 0){
    ledsIst[i].red = 0;
    ledsIst[i].green = 0;
    ledsIst[i].blue = 0;
    return;
  }
 
  if(state[i] == 4){
    ledsIst[i].red = int(leds[i].red);
    ledsIst[i].blue = int(leds[i].blue);
    ledsIst[i].green = int(leds[i].green);
  }else if(state[i] > 4){
    int f = ((state[i]-4)*2);
    ledsIst[i].red = int(leds[i].red / f);
    ledsIst[i].blue = int(leds[i].blue / f);
    ledsIst[i].green = int(leds[i].green / f);
  }else if(state[i] < 4){
    int f = ((4-state[i])*2);
    ledsIst[i].red = int(leds[i].red / f);
    ledsIst[i].blue = int(leds[i].blue / f);
    ledsIst[i].green = int(leds[i].green / f);
  }
 
  state[i]++;
  if(state[i] == 15){
    state[i] = 0;
  }
}
 
void loop() {
  for(int i=0; i<strip.numPixels(); i++) {
    if( random(0,100) < PERCENT_SPAWN && state[i]==0){
      C col = colors[random(0,NUM_COLORS)];
      setLED(i,col);
    }
    dimLED(i);
  }
 
  for(int i=0; i<strip.numPixels(); i++) {
    C col = ledsIst[i];
    strip.setPixelColor(i, col.red, col.green, col.blue);
  }
 
  strip.show();
  delay(70);
}
  • projekte/berlinbadge_rev1.txt
  • Zuletzt geändert: 2020/10/18 14:01
  • (Externe Bearbeitung)