From a9c18a77769182c8e51f074daf3cd5f873a39bba Mon Sep 17 00:00:00 2001 From: Kees Guequierre Date: Thu, 17 Oct 2019 18:16:22 +0200 Subject: [PATCH] pong dingus --- DisplaydriverPong1.ino | 279 +++++++++++++++++++++++++++++++++++++++++ bitmaps.txt | 36 ++++++ convert.php | 68 ++++++++++ font.h | 4 + ht1632.h | 35 ++++++ 5 files changed, 422 insertions(+) create mode 100644 DisplaydriverPong1.ino create mode 100644 bitmaps.txt create mode 100644 convert.php create mode 100644 font.h create mode 100644 ht1632.h diff --git a/DisplaydriverPong1.ino b/DisplaydriverPong1.ino new file mode 100644 index 0000000..a110d68 --- /dev/null +++ b/DisplaydriverPong1.ino @@ -0,0 +1,279 @@ +#include +#include "ht1632.h" + +#define P1WIN 0 +#define P2WIN 1 +#define PONG 2 +#define FIVE 3 +#define FOUR 4 +#define THREE 5 +#define TWO 6 +#define ONE 7 +#define CLS 8 +/* + * Set these constants to the values of the pins connected to the SureElectronics Module + */ +static const byte ht1632_data = 6; // Data pin (pin 7) +static const byte ht1632_wrclk = 7; // Write clock pin (pin 5) +static const byte ht1632_cs[] = {8,9}; // Chip Select (1, 2, 3, or 4) +static const byte ht1632_displays = 2; // Number of displays + +static const byte bitmaps[][128]={ + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,8,3,12,6,6,12,3,8,1,0,0,15,15,15,15,0,3,0,6,0,12,0,12,0,6,0,3,15,15,15,15,0,0,0,0,15,15,15,15,0,0,0,0,15,15,15,15,6,0,3,0,1,8,0,12,0,6,0,3,15,15,15,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,15,15,15,15,0,3,0,6,0,12,0,12,0,6,0,3,15,15,15,15,0,0,0,0,15,15,15,15,0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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,3,12,7,12,15,12,11,13,11,13,3,15,3,6,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,3,15,15,15,15,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} + }; + + +byte ht1632_shadowram[128]; + +/* + * ht1632_writebits + * Write bits (up to 8) to h1632 on pins ht1632_data, ht1632_wrclk + * Chip is assumed to already be chip-selected + * Bits are shifted out from MSB to LSB, with the first bit sent + * being (bits & firstbit), shifted till firsbit is zero. + */ +void ht1632_chipselect(byte chipno) +{ + digitalWrite(chipno, 0); +} + +void ht1632_chipfree(byte chipno) +{ + digitalWrite(chipno, 1); +} + +void ht1632_writebits (byte bits, byte firstbit) +{ + while (firstbit) { + digitalWrite(ht1632_wrclk, LOW); + if (bits & firstbit) { + digitalWrite(ht1632_data, HIGH); + } + else { + digitalWrite(ht1632_data, LOW); + } + digitalWrite(ht1632_wrclk, HIGH); + firstbit >>= 1; + } +} + +static void ht1632_sendcmd (byte command,byte cs) +{ + ht1632_chipselect(cs); // Select chip + ht1632_writebits(HT1632_ID_CMD, 1<<2); // send 3 bits of id: COMMMAND + ht1632_writebits(command, 1<<7); // send the actual command + ht1632_writebits(0, 1); /* one extra dont-care bit in commands. */ + ht1632_chipfree(cs); //done +} + +static void ht1632_senddata (byte address, byte data, byte cs) +{ + ht1632_chipselect(cs); // Select chip + ht1632_writebits(HT1632_ID_WR, 1<<2); // send ID: WRITE to RAM + ht1632_writebits(address, 1<<6); // Send address + ht1632_writebits(data, 1<<3); // send 4 bits of data + ht1632_chipfree(cs); // done +} + +static void ht1632_sendshadowram () +{ + for(byte cs=0;cs7) + offset = y>>3; + bitval = 8>>(y&3); // compute which bit will need set + addr = (x<<1) + ((y&B00000111)>>2) + (offset<<6); // compute which memory word this is in + if (val) { // Modify the shadow memory + ht1632_shadowram[addr] |= bitval; + } else { + ht1632_shadowram[addr] &= ~bitval; + } + // Now copy the new memory value to the display + //for(byte j=0;j231){X=231; XRC=-XRC; YRC=random(0,16);} + if(X<23) { + if((p1b>Y-13) & (p1b>1; + } else { + p2s++; + delay(500); + Y=32; + X=128; + XRC=8; + } + } + if(Y>127) {Y=127; YRC=-YRC;} + if(Y<0) {Y=0; YRC=-YRC;} + + plot(X>>3,Y>>3,1); + if((X>>3!=Xo>>3) | (Y>>3!=Yo>>3)) plot(Xo>>3,Yo>>3,0); + Xo=X; + Yo=Y; + +// plot score +// if(p1s>0) plot(0,p1s-1,1); +// if(p2s>0) plot(31,8-p2s,1); + + if(random(0,2)==1){ + if(random(0,50)==1) p1s++; + if(p1s>8){ + p1s=0; + for(i=0;i<8;i++) {plot(0,i,0);} + } + } + + + +// for(i=0;i<8;i++) {plot(2,i,0);} + // p1b=analogRead(1)>>6; + +// if(p1b>Y){ +// p1b+=bs; +// }else{ +// p1b+=-bs; +// } + +// if(p1b<8) {plot(2,0,1);plot(2,1,1);plot(2,2,1);p1b=7;} +// else if(p1b>55) {plot(2,5,1);plot(2,6,1);plot(2,7,1);p1b=56;} +// else {plot(2,(p1b>>3)-1,1);plot(2,(p1b>>3),1);plot(2,(p1b>>3)+1,1);} + +// for(i=0;i<8;i++) {plot(29,i,0);} +// if(p2b>Y){ +// p2b+=bs; +// }else{ +// p2b+=-bs; +// } + // p2b=Y; + // if(p2b<8) {plot(29,0,1);plot(29,1,1);plot(29,2,1); p2b=7;} + // else if(p2b>55) {plot(29,5,1);plot(29,6,1);plot(29,7,1);p2b=56;} + // else {plot(29,(p2b>>3)-1,1);plot(29,(p2b>>3),1);plot(29,(p2b>>3)+1,1);} + delay(100); + } + + if(p1s==8){ + showbitmap(P1WIN); + } else { + showbitmap(P2WIN); + } + delay(1000); + +} +void test(){ + plot(1,0,1); + plot(1,1,1); + plot(1,2,1); + plot(1,3,1); + plot(1,4,1); + plot(1,5,1); + plot(1,6,1); + plot(1,7,1); + plot(1,8,1); + plot(1,9,1); + plot(2,8,1); + +} + +void loop(){ + showbitmap(PONG); +// delay(500); +// showbitmap(FIVE); +// delay(500); +// showbitmap(FOUR); +// delay(500); +// showbitmap(THREE); +// delay(500); +// showbitmap(TWO); +// delay(500); +// showbitmap(ONE); +// delay(500); +// showbitmap(CLS); +// game(); +// test(); +} diff --git a/bitmaps.txt b/bitmaps.txt new file mode 100644 index 0000000..d500f6d --- /dev/null +++ b/bitmaps.txt @@ -0,0 +1,36 @@ +-- title screen +0012345678901234567890123456789012 +01.##### ..####..#...##..####..##. +02.######.######.##..##.######.##. +03.##..##.##..##.###.##.##..##.##. +04.##..##.##..##.######.##.....##. +05.######.##..##.##.###.##.....##. +06.#####..##..##.##..##.##.....##. +07.##.....##..##.##..##.##.....##. +08.##.....##..##.##..##.##.....##. +09.##.....##..##.##..##.##.....##. +10.##.....##..##.##..##.##.....##. +11.##.....##..##.##..##.##.###.##. +12.##.....##..##.##..##.##.###.##. +13.##.....##..##.##..##.##..##.##. +14.##.....##..##.##..##.##..##.... +15.##.....######.##..##.######.##. +16.##......####..##..##..####..##. +-- anim 1 +0012345678901234567890123456789012 +01##..##..##..##..##..##..##..##.. +02#..##..##..##..##..##..##..##..# +03..##..##..##..##..##..##..##..## +04.##..##..##..##..##..##..##..##. +05##..##..##..##..##..##..##..##.. +06#..##..##..##..##..##..##..##..# +07..##..##..##..##..##..##..##..## +08.##..##..##..##..##..##..##..##. +09.##..##..##..##..##..##..##..##. +10..##..##..##..##..##..##..##..## +11#..##..##..##..##..##..##..##..# +12##..##..##..##..##..##..##..##.. +13.##..##..##..##..##..##..##..##. +14..##..##..##..##..##..##..##..## +15#..##..##..##..##..##..##..##..# +16##..##..##..##..##..##..##..##.. diff --git a/convert.php b/convert.php new file mode 100644 index 0000000..78cc25a --- /dev/null +++ b/convert.php @@ -0,0 +1,68 @@ +$max) $max=strlen($data0); + for($i=0;$i + + diff --git a/font.h b/font.h new file mode 100644 index 0000000..b5f445d --- /dev/null +++ b/font.h @@ -0,0 +1,4 @@ +char f_width[95] PROGMEM={3,2,4,6,8,8,7,2,3,3,8,4,3,4,2,7,6,4,6,6,6,6,6,6,6,6,2,3,4,4,4,6,6,6,6,6,6,6,6,6,6,4,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,3,7,3,4,4,3,6,6,6,6,6,5,6,6,2,5,6,3,6,6,6,6,6,6,6,5,6,6,6,6,6,6,4,2,4,6}; +char f_upper[760] PROGMEM={0,0,0,0,0,0,0,0,15,0,0,0,0,0,0,0,12,0,12,0,0,0,0,0,1,3,1,3,1,0,0,0,2,5,5,15,5,5,4,0,4,10,4,1,2,4,8,0,6,9,9,7,1,2,0,0,12,0,0,0,0,0,0,0,7,8,0,0,0,0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0,0,0,2,14,2,0,0,0,0,0,4,2,2,12,0,0,0,0,14,0,0,8,6,0,0,0,14,2,2,2,2,0,0,0,14,0,0,0,14,0,0,0,14,0,0,0,14,0,0,0,12,2,2,2,12,0,0,0,14,0,0,0,0,0,0,0,12,2,6,2,13,0,0,0,14,0,0,0,14,0,0,0,4,2,2,2,12,0,0,0,0,0,14,0,0,0,0,0,12,2,2,6,12,0,0,0,0,12,2,12,0,0,0,0,14,4,8,4,14,0,0,0,6,8,0,8,6,0,0,0,0,0,14,0,0,0,0,0,6,10,2,2,2,0,0,0,14,2,0,0,0,0,0,0,0,0,0,8,4,2,0,0,2,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,12,10,10,10,14,0,0,0,14,10,10,10,4,0,0,0,12,2,2,2,4,0,0,0,4,10,10,10,14,0,0,0,12,10,10,10,8,0,0,0,8,14,8,0,0,0,0,0,8,5,5,5,14,0,0,0,14,8,8,8,6,0,0,0,14,0,0,0,0,0,0,0,2,1,1,14,0,0,0,0,14,0,8,4,2,0,0,0,0,14,0,0,0,0,0,0,14,0,0,0,14,0,0,0,14,0,0,0,14,0,0,0,12,2,2,2,12,0,0,0,15,4,4,4,8,0,0,0,8,4,4,4,15,0,0,0,14,0,0,0,0,0,0,0,0,10,10,10,4,0,0,0,0,12,2,2,0,0,0,0,12,2,2,4,14,0,0,0,8,4,2,4,8,0,0,0,12,2,4,2,12,0,0,0,2,4,8,4,2,0,0,0,8,5,5,5,14,0,0,0,2,6,10,2,2,0,0,0,0,12,2,0,0,0,0,0,14,0,0,0,0,0,0,0,2,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; + diff --git a/ht1632.h b/ht1632.h new file mode 100644 index 0000000..08d97e3 --- /dev/null +++ b/ht1632.h @@ -0,0 +1,35 @@ +/* + * ht1632.h + * defintions for Holtek ht1632 LED driver. + */ + + +#if !defined(DEBUGPRINT) +#define DEBUGPRINT(fmt, args...) +#endif + +/* + * commands written to the chip consist of a 3 bit "ID", followed by + * either 9 bits of "Command code" or 7 bits of address + 4 bits of data. + */ +#define HT1632_ID_CMD 4 /* ID = 100 - Commands */ +#define HT1632_ID_RD 6 /* ID = 110 - Read RAM */ +#define HT1632_ID_WR 5 /* ID = 101 - Write RAM */ + +#define HT1632_CMD_SYSDIS 0x00 /* CMD= 0000-0000-x Turn off oscil */ +#define HT1632_CMD_SYSON 0x01 /* CMD= 0000-0001-x Enable system oscil */ +#define HT1632_CMD_LEDOFF 0x02 /* CMD= 0000-0010-x LED duty cycle gen off */ +#define HT1632_CMD_LEDON 0x03 /* CMD= 0000-0011-x LEDs ON */ +#define HT1632_CMD_BLOFF 0x08 /* CMD= 0000-1000-x Blink ON */ +#define HT1632_CMD_BLON 0x09 /* CMD= 0000-1001-x Blink Off */ +#define HT1632_CMD_SLVMD 0x10 /* CMD= 0001-00xx-x Slave Mode */ +#define HT1632_CMD_MSTMD 0x14 /* CMD= 0001-01xx-x Master Mode */ +#define HT1632_CMD_RCCLK 0x18 /* CMD= 0001-10xx-x Use on-chip clock */ +#define HT1632_CMD_EXTCLK 0x1C /* CMD= 0001-11xx-x Use external clock */ +#define HT1632_CMD_COMS00 0x20 /* CMD= 0010-ABxx-x commons options */ +#define HT1632_CMD_COMS01 0x24 /* CMD= 0010-ABxx-x commons options */ +#define HT1632_CMD_COMS10 0x28 /* CMD= 0010-ABxx-x commons options */ +#define HT1632_CMD_COMS11 0x2C /* CMD= 0010-ABxx-x commons options */ +#define HT1632_CMD_PWM 0xA0 /* CMD= 101x-PPPP-x PWM duty cycle */ + +