diff --git a/platformio.ini b/platformio.ini index 4e203d9..2adc984 100644 --- a/platformio.ini +++ b/platformio.ini @@ -8,6 +8,9 @@ ; Please visit documentation for the other options and examples ; http://docs.platformio.org/page/projectconf.html +[platformio] +env_default = leonardo + [env:attiny2313] platform = atmelavr board = attiny2313 @@ -18,4 +21,9 @@ upload_protocol = stk500v1 upload_flags = -P$UPLOAD_PORT -b$UPLOAD_SPEED ; values upload_port = /dev/ttyUSB0 -upload_speed = 19200 \ No newline at end of file +upload_speed = 19200 + +[env:leonardo] +platform = atmelavr +board = leonardo +framework = arduino \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index de7b395..3e9d52a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,9 +1,88 @@ #include +/* +for cheap Chinese 64 dots LED-Projector + +Board has unmarked chip in socket - pin layout fits to ATTiny 2313 an 4313 +the LEDS are connected to 8 pcs 74HC595 + + + --u-- +RST 1 20 VCC +NC (0) 2 19 (16) IN SCK +NC (1) 3 18 (15) IN MISO +XTAL 4 17 (14) IN MOSI +XTAL 5 16 (13) IN +OUT (4) 6 15 (12) IN +OUT (5) 7 14 (11) IN +OUT (6) 8 13 (10) IN +NC (7) 9 12 (9) MIC +GND 10 11 (8) IN + ----- + +() = Arduino Pins +RST = Reset - 10K to GND, 10uF to VCC +XTAL = 16 MHz Crystal +IN = switches +MIC = Input from microphone amplifier (LM358) + + +*/ + +#define LATCHPIN 6 +#define DATAPIN 4 +#define CLOCKPIN 5 +byte ledsData[8]; + +byte currentled = 0; + +void clear() { + for (int i=0; i < 8; i++) { + // low is led on + ledsData[i] = 255; + } +} + +void writebuffer(byte ledNr) { + byte chipNr = ledNr / 8; + byte pinNr = ledNr % 8; + if(chipNr < 8) { + bitWrite(ledsData[chipNr], pinNr, LOW); + } +} + +void writexy(byte x, byte y) { + byte lednr = x*8 + y; + writebuffer(lednr); +} + +void pushout() { + digitalWrite(LATCHPIN, LOW); + for(int i = 8-1; i>=0; i--) { + shiftOut(DATAPIN, CLOCKPIN, MSBFIRST, ledsData[i]); + } + digitalWrite(LATCHPIN, HIGH); +} + void setup() { - // put your setup code here, to run once: + pinMode(LATCHPIN, OUTPUT); + pinMode(DATAPIN, OUTPUT); + pinMode(CLOCKPIN, OUTPUT); + + clear(); + pushout(); + } void loop() { - // put your main code here, to run repeatedly: -} \ No newline at end of file + clear(); + writebuffer(currentled); + + pushout(); + + currentled++; + if (currentled >=64) { + currentled = 0; + } + delay(100); +}