![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
9 tile screen working with one image space, platform for development
main.cpp@0:8b26631e8c70, 2012-03-06 (annotated)
- Committer:
- rsavitski
- Date:
- Tue Mar 06 19:58:34 2012 +0000
- Revision:
- 0:8b26631e8c70
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rsavitski | 0:8b26631e8c70 | 1 | #include "mbed.h" |
rsavitski | 0:8b26631e8c70 | 2 | #include "ledScreen.h" |
rsavitski | 0:8b26631e8c70 | 3 | |
rsavitski | 0:8b26631e8c70 | 4 | // screen instance |
rsavitski | 0:8b26631e8c70 | 5 | ledScreen screen; |
rsavitski | 0:8b26631e8c70 | 6 | |
rsavitski | 0:8b26631e8c70 | 7 | // sin lookup table and related functions |
rsavitski | 0:8b26631e8c70 | 8 | unsigned char sinlut[256]; |
rsavitski | 0:8b26631e8c70 | 9 | |
rsavitski | 0:8b26631e8c70 | 10 | void initSinLut() { |
rsavitski | 0:8b26631e8c70 | 11 | for (int i=0; i<256; i++) |
rsavitski | 0:8b26631e8c70 | 12 | sinlut[i] = cos((float)i / 256.0 * (3.14159265 * 2))*127 + 128; |
rsavitski | 0:8b26631e8c70 | 13 | } |
rsavitski | 0:8b26631e8c70 | 14 | |
rsavitski | 0:8b26631e8c70 | 15 | inline unsigned char lut_sin(int x) { |
rsavitski | 0:8b26631e8c70 | 16 | |
rsavitski | 0:8b26631e8c70 | 17 | return (x>0)?sinlut[x%256]:sinlut[(-x)%256]; |
rsavitski | 0:8b26631e8c70 | 18 | } |
rsavitski | 0:8b26631e8c70 | 19 | |
rsavitski | 0:8b26631e8c70 | 20 | |
rsavitski | 0:8b26631e8c70 | 21 | // Example frame makes: |
rsavitski | 0:8b26631e8c70 | 22 | |
rsavitski | 0:8b26631e8c70 | 23 | |
rsavitski | 0:8b26631e8c70 | 24 | //rainbow |
rsavitski | 0:8b26631e8c70 | 25 | void makeFrame1(unsigned char* data) { |
rsavitski | 0:8b26631e8c70 | 26 | |
rsavitski | 0:8b26631e8c70 | 27 | static int time=0; |
rsavitski | 0:8b26631e8c70 | 28 | time++; |
rsavitski | 0:8b26631e8c70 | 29 | |
rsavitski | 0:8b26631e8c70 | 30 | // override data with a intensity gradient test pattern |
rsavitski | 0:8b26631e8c70 | 31 | for (int x=0; x<3*16; x++) { |
rsavitski | 0:8b26631e8c70 | 32 | for (int y=0; y<48; y++) { |
rsavitski | 0:8b26631e8c70 | 33 | |
rsavitski | 0:8b26631e8c70 | 34 | int i = (x + y*(16*3)) * 3; // figure out the memory location |
rsavitski | 0:8b26631e8c70 | 35 | |
rsavitski | 0:8b26631e8c70 | 36 | data[i] = lut_sin((x+y)*255/48+(time/2)%256); //(sin((float)(x+time)/15.0)+1.0)*128 ; // red |
rsavitski | 0:8b26631e8c70 | 37 | data[i+1] = lut_sin(((x+y)*255/48+(time/2)+ 85)%256); //(sin((float)(x+time)/15.0)+1.0)*128 ; // red |
rsavitski | 0:8b26631e8c70 | 38 | data[i+2] = lut_sin(((x+y)*255/48+(time/2)+170)%256); //(sin((float)(x+time)/15.0)+1.0)*128 ; // red |
rsavitski | 0:8b26631e8c70 | 39 | } |
rsavitski | 0:8b26631e8c70 | 40 | } |
rsavitski | 0:8b26631e8c70 | 41 | |
rsavitski | 0:8b26631e8c70 | 42 | } |
rsavitski | 0:8b26631e8c70 | 43 | |
rsavitski | 0:8b26631e8c70 | 44 | //cool lines |
rsavitski | 0:8b26631e8c70 | 45 | void makeFrame2(unsigned char* data) { |
rsavitski | 0:8b26631e8c70 | 46 | |
rsavitski | 0:8b26631e8c70 | 47 | static int time=0; |
rsavitski | 0:8b26631e8c70 | 48 | time++; |
rsavitski | 0:8b26631e8c70 | 49 | |
rsavitski | 0:8b26631e8c70 | 50 | // override data with a intensity gradient test pattern |
rsavitski | 0:8b26631e8c70 | 51 | for (int x=0; x<3*16; x++) { |
rsavitski | 0:8b26631e8c70 | 52 | for (int y=0; y<16; y++) { |
rsavitski | 0:8b26631e8c70 | 53 | |
rsavitski | 0:8b26631e8c70 | 54 | int i = (x + y*(16*3)) * 3; // figure out the memory location |
rsavitski | 0:8b26631e8c70 | 55 | |
rsavitski | 0:8b26631e8c70 | 56 | data[i] = lut_sin(x*255/48+(time)%256 + y*16); //(sin((float)(x+time)/15.0)+1.0)*128 ; // red |
rsavitski | 0:8b26631e8c70 | 57 | data[i+1] = lut_sin(x*255/48+(time)%256 + y*16 + 85); //(sin((float)(x+time)/15.0)+1.0)*128 ; // red |
rsavitski | 0:8b26631e8c70 | 58 | data[i+2] = lut_sin(x*255/48+(time)%256 + y*16 + 170); //(sin((float)(x+time)/15.0)+1.0)*128 ; // red |
rsavitski | 0:8b26631e8c70 | 59 | } |
rsavitski | 0:8b26631e8c70 | 60 | } |
rsavitski | 0:8b26631e8c70 | 61 | |
rsavitski | 0:8b26631e8c70 | 62 | } |
rsavitski | 0:8b26631e8c70 | 63 | |
rsavitski | 0:8b26631e8c70 | 64 | // static gradients |
rsavitski | 0:8b26631e8c70 | 65 | void makeFrame3(unsigned char* data) { |
rsavitski | 0:8b26631e8c70 | 66 | |
rsavitski | 0:8b26631e8c70 | 67 | static int time=0; |
rsavitski | 0:8b26631e8c70 | 68 | time++; |
rsavitski | 0:8b26631e8c70 | 69 | |
rsavitski | 0:8b26631e8c70 | 70 | // override data with a intensity gradient test pattern |
rsavitski | 0:8b26631e8c70 | 71 | for (int x=0; x<3*16; x++) { |
rsavitski | 0:8b26631e8c70 | 72 | for (int y=0; y<16; y++) { |
rsavitski | 0:8b26631e8c70 | 73 | |
rsavitski | 0:8b26631e8c70 | 74 | int i = (x + y*(16*3)) * 3; // figure out the memory location |
rsavitski | 0:8b26631e8c70 | 75 | |
rsavitski | 0:8b26631e8c70 | 76 | data[i] = x*256/48; //(sin((float)(x+time)/15.0)+1.0)*128 ; // red |
rsavitski | 0:8b26631e8c70 | 77 | data[i+1] = 0; // green |
rsavitski | 0:8b26631e8c70 | 78 | data[i+2] = y*256/16; //(i/3)%256 ; // blue |
rsavitski | 0:8b26631e8c70 | 79 | } |
rsavitski | 0:8b26631e8c70 | 80 | } |
rsavitski | 0:8b26631e8c70 | 81 | |
rsavitski | 0:8b26631e8c70 | 82 | } |
rsavitski | 0:8b26631e8c70 | 83 | |
rsavitski | 0:8b26631e8c70 | 84 | |
rsavitski | 0:8b26631e8c70 | 85 | void makeFrame33(unsigned char* data) { |
rsavitski | 0:8b26631e8c70 | 86 | |
rsavitski | 0:8b26631e8c70 | 87 | static int time=0; |
rsavitski | 0:8b26631e8c70 | 88 | time++; |
rsavitski | 0:8b26631e8c70 | 89 | |
rsavitski | 0:8b26631e8c70 | 90 | for (int x=0; x<3*16; x++) { |
rsavitski | 0:8b26631e8c70 | 91 | for (int y=0; y<48; y++) { |
rsavitski | 0:8b26631e8c70 | 92 | |
rsavitski | 0:8b26631e8c70 | 93 | int i = (x + y*(16*3)) * 3; // figure out the memory location |
rsavitski | 0:8b26631e8c70 | 94 | |
rsavitski | 0:8b26631e8c70 | 95 | data[i] = x*256/48; //(sin((float)(x+time)/15.0)+1.0)*128 ; // red |
rsavitski | 0:8b26631e8c70 | 96 | data[i+1] = 0; // green |
rsavitski | 0:8b26631e8c70 | 97 | data[i+2] = y*256/48; //(i/3)%256 ; // blue |
rsavitski | 0:8b26631e8c70 | 98 | } |
rsavitski | 0:8b26631e8c70 | 99 | } |
rsavitski | 0:8b26631e8c70 | 100 | } |
rsavitski | 0:8b26631e8c70 | 101 | |
rsavitski | 0:8b26631e8c70 | 102 | int main() |
rsavitski | 0:8b26631e8c70 | 103 | { |
rsavitski | 0:8b26631e8c70 | 104 | |
rsavitski | 0:8b26631e8c70 | 105 | // framebuffer on client side |
rsavitski | 0:8b26631e8c70 | 106 | unsigned char imageSource[256*3*3*3] = { 0 }; |
rsavitski | 0:8b26631e8c70 | 107 | |
rsavitski | 0:8b26631e8c70 | 108 | // prepare sin lookup table (optional) |
rsavitski | 0:8b26631e8c70 | 109 | initSinLut(); |
rsavitski | 0:8b26631e8c70 | 110 | |
rsavitski | 0:8b26631e8c70 | 111 | // start the screen output, which will keep outputting the frames that are in its internal buffer (updated via .transformFrame) |
rsavitski | 0:8b26631e8c70 | 112 | screen.start(); |
rsavitski | 0:8b26631e8c70 | 113 | |
rsavitski | 0:8b26631e8c70 | 114 | while (1) { |
rsavitski | 0:8b26631e8c70 | 115 | |
rsavitski | 0:8b26631e8c70 | 116 | makeFrame1(imageSource); // prepare framebuffer with current frame |
rsavitski | 0:8b26631e8c70 | 117 | screen.transformFrame(imageSource); // write framebuffer to output framebuffer |
rsavitski | 0:8b26631e8c70 | 118 | wait_ms(0.5); // slow down the framerate (optional) |
rsavitski | 0:8b26631e8c70 | 119 | } |
rsavitski | 0:8b26631e8c70 | 120 | |
rsavitski | 0:8b26631e8c70 | 121 | } |