ledprojector/src/main.cpp

154 lines
2.7 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)
2018-01-14 22:21:27 +01:00
*/
2018-01-14 20:27:20 +01:00
2018-01-14 22:21:27 +01:00
/*
x
XXXXXXX
XX XXX XX
XXXXXXXXXXX
X XXXXXXX X
X X X X
XX XX
2018-01-14 20:27:20 +01:00
*/
2018-01-14 22:21:27 +01:00
byte invaderA_1[11] = {112,24,125,182,188,60,188,182,125,24,112};
2018-01-14 21:28:36 +01:00
#define LATCHPIN 5
2018-01-14 20:27:20 +01:00
#define DATAPIN 4
2018-01-14 21:28:36 +01:00
#define CLOCKPIN 6
2018-01-14 20:27:20 +01:00
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);
}
2018-01-14 21:28:36 +01:00
byte rowmask[8] = {5,3,1,0,2,4,6,7};
2018-01-14 20:27:20 +01:00
void pushout() {
digitalWrite(LATCHPIN, LOW);
for(int i = 8-1; i>=0; i--) {
2018-01-14 21:28:36 +01:00
byte row = rowmask[i];
shiftOut(DATAPIN, CLOCKPIN, MSBFIRST, ledsData[row]);
2018-01-14 20:27:20 +01:00
}
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
}
2018-01-14 22:21:27 +01:00
void drawinvader(int xposition, int yposition) {
// TODO yposition
for (int x=0; x<=11; x++) {
int screenx = x+xposition;
if (screenx >=0 && screenx < 8) {
for (int y=0; y<8; y++) {
int screeny = y+yposition;
if (screeny >=0 && screeny < 8) {
if (bitRead(invaderA_1[x],y) == HIGH ) {
writexy(screenx,screeny);
}
}
}
}
}
}
2018-01-14 21:28:36 +01:00
byte currentcol=1;
bool direction = true;
2018-01-14 22:21:27 +01:00
int invaderstart = -12;
int invaderend = 8;
int invaderposition = invaderstart;
2018-01-14 01:39:29 +01:00
void loop() {
2018-01-14 20:27:20 +01:00
clear();
2018-01-14 21:28:36 +01:00
2018-01-14 22:21:27 +01:00
/*
2018-01-14 21:28:36 +01:00
// x-line
for(byte i=0; i<8; i++) {
writexy(i,currentcol-1);
}
// y line
for(byte i=0; i<8; i++) {
writexy(currentcol-1,i);
}
2018-01-14 22:21:27 +01:00
*/
drawinvader(invaderposition,0);
invaderposition++;
if (invaderposition >=invaderend) {
invaderposition = invaderstart;
}
2018-01-14 20:27:20 +01:00
pushout();
2018-01-14 22:21:27 +01:00
/*
2018-01-14 21:28:36 +01:00
if(direction) {
currentcol++;
} else {
currentcol--;
}
if (currentcol >8) {
currentcol = 7;
direction = false;
}
if (currentcol <=0) {
currentcol=2;
direction = true;
2018-01-14 20:27:20 +01:00
}
2018-01-14 22:21:27 +01:00
*/
delay(300);
2018-01-14 20:27:20 +01:00
}