A demo for Adafruit 64x32 demo with PWM
Dependencies: mbed-rtos BufferedSerial Adafruit_GFX_MBED LedMatrix-PWM FastIO mbed-dev
Revision 4:3e25a10c202c, committed 2017-10-24
- Comitter:
- davidr99
- Date:
- Tue Oct 24 03:02:51 2017 +0000
- Parent:
- 3:d83b9737e764
- Commit message:
- Changed to be a faster interrupt and use less time to update display
Changed in this revision
diff -r d83b9737e764 -r 3e25a10c202c BufferedSerial.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BufferedSerial.lib Tue Oct 24 03:02:51 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/sam_grove/code/BufferedSerial/#a0d37088b405
diff -r d83b9737e764 -r 3e25a10c202c FastIO.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FastIO.lib Tue Oct 24 03:02:51 2017 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/davidr99/code/FastIO/#929068181dea
diff -r d83b9737e764 -r 3e25a10c202c LedMatrix-PWM.lib --- a/LedMatrix-PWM.lib Wed Oct 11 00:38:39 2017 +0000 +++ b/LedMatrix-PWM.lib Tue Oct 24 03:02:51 2017 +0000 @@ -1,1 +1,1 @@ -https://os.mbed.com/users/davidr99/code/LedMatrix-PWM/#cdc5e3a73147 +https://os.mbed.com/users/davidr99/code/LedMatrix-PWM/#99abd7449a45
diff -r d83b9737e764 -r 3e25a10c202c main.cpp --- a/main.cpp Wed Oct 11 00:38:39 2017 +0000 +++ b/main.cpp Tue Oct 24 03:02:51 2017 +0000 @@ -6,6 +6,9 @@ #include "mbed.h" #include "rtos.h" #include "LedMatrix.h" +#include "BufferedSerial.h" + +BufferedSerial pc(USBTX, USBRX, 1024); // tx, rx LedMatrix matrix; @@ -14,13 +17,123 @@ matrix.Paint(); } +int getNextByte() +{ + char value = 0; + + while(pc.readable() == 0); + value = pc.getc(); + return value; +} + int main() { Ticker ticker; - ticker.attach(PaintThread, 0.003); + matrix.Init(); + + pc.baud(460800); + + #if defined(TARGET_STM32F767ZI) + ticker.attach_us(PaintThread, 15); + #elif defined(TARGET_STM32F303K8) + ticker.attach_us(PaintThread, 25); + #endif + + uint16_t currentX = 0, currentY = 0; while(1) { + + /* + int c = getNextByte(); // Read byte from master + + switch (c) + { + case 'L': // Location + currentX = (getNextByte() << 8) + getNextByte(); + currentY = (getNextByte() << 8) + getNextByte(); + pc.printf("X: %d, Y: %d\n", currentX, currentY); + break; + + case 'G': // Set background + { + uint16_t c = getNextByte() | (getNextByte() << 8); + + for(int y=0;y<HEIGHT;y++) + { + for(int x=0;x<WIDTH;x++) + { + matrix.drawPixel(x, y, c); + } + } + } + break; + + case 'B': // Load buffer + for(int y=0;y<HEIGHT;y++) + { + for(int x=0;x<WIDTH;x++) + { + uint16_t c = getNextByte() | (getNextByte() << 8); + matrix.drawPixel(x, y, c); + } + } + break; + + case 'C': // Color + { + uint16_t c = getNextByte() | (getNextByte() << 8); + matrix.drawPixel(currentX, currentY, c); + + currentX++; + if (currentX >= WIDTH) + { + currentX = 0; + currentY++; + } + + if (currentY >= HEIGHT) + { + currentY = 0; + } + } + break; + + case 'D': // Double Buffer + { + bool dBuffer = getNextByte() == 1; + matrix.SetDoubleBuffer(dBuffer); + } + break; + + case 'S': // Swap Buffers + { + bool copyBuffer = getNextByte() == 1; + matrix.Swap(copyBuffer); + } + break; + + case 'T': // Text + { + int16_t x = getNextByte() | (getNextByte() << 8); + int16_t y = getNextByte() | (getNextByte() << 8); + int size = getNextByte(); + uint16_t color = getNextByte() | (getNextByte() << 8); + + matrix.setCursor(x, y); + matrix.setTextColor(color); + matrix.setTextSize(size); + + int length = getNextByte(); + for(int c = 0; c< length;c++) + { + matrix.print((char) getNextByte()); + } + } + break; + } + */ + /* for(int c=0;c<64;c++) { matrix.setCursor(20, 12); @@ -30,7 +143,8 @@ Thread::wait(200); } - for(int x=0;x<64;x++) + */ + for(int x=0;x<WIDTH;x++) { for(int y=0;y<32;y++) { @@ -41,19 +155,19 @@ Thread::wait(5000); for(int c=0; c<16; c++) { - for(int x=c; x<(63-c); x++) {// Top side + for(int x=c; x<((WIDTH-1)-c); x++) {// Top side matrix.drawPixel(x,c,matrix.Color444(c, 0, 0)); Thread::wait(10); } - for(int y=c; y<(31-c); y++) {// Right side - matrix.drawPixel(63-c,y, matrix.Color444(0, c, 0)); + for(int y=c; y<((HEIGHT-1)-c); y++) {// Right side + matrix.drawPixel((WIDTH-1)-c,y, matrix.Color444(0, c, 0)); Thread::wait(10); } - for(int x=(63-c); x>=c; x--) {// Bottom side - matrix.drawPixel(x,(31-c), matrix.Color444(0, 0, c)); + for(int x=((WIDTH-1)-c); x>=c; x--) {// Bottom side + matrix.drawPixel(x,((HEIGHT-1)-c), matrix.Color444(0, 0, c)); Thread::wait(10); } - for(int y=(31-c); y>=c; y--) { // Left side + for(int y=((HEIGHT-1)-c); y>=c; y--) { // Left side matrix.drawPixel(c,y, matrix.Color444(0, c, 0)); Thread::wait(10); }
diff -r d83b9737e764 -r 3e25a10c202c mbed-dev.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-dev.lib Tue Oct 24 03:02:51 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-dev/#af195413fb11
diff -r d83b9737e764 -r 3e25a10c202c mbed.bld --- a/mbed.bld Wed Oct 11 00:38:39 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/235179ab3f27 \ No newline at end of file