ledprojector/src/main.cpp

89 lines
1.5 KiB
C++
Raw Normal View History

2018-01-14 01:39:29 +01:00
#include <Arduino.h>
2018-01-14 20:27:20 +01:00
/*
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);
}
2018-01-14 01:39:29 +01:00
void setup() {
2018-01-14 20:27:20 +01:00
pinMode(LATCHPIN, OUTPUT);
pinMode(DATAPIN, OUTPUT);
pinMode(CLOCKPIN, OUTPUT);
clear();
pushout();
2018-01-14 01:39:29 +01:00
}
void loop() {
2018-01-14 20:27:20 +01:00
clear();
writebuffer(currentled);
pushout();
currentled++;
if (currentled >=64) {
currentled = 0;
}
delay(100);
}