Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Revision 0:0def0023f900, committed 2015-12-08
- Comitter:
- mbedobsza
- Date:
- Tue Dec 08 21:42:56 2015 +0000
- Commit message:
- 13B_slave-fra221-6476
Changed in this revision
diff -r 000000000000 -r 0def0023f900 iteadstudio_colourshield.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/iteadstudio_colourshield.cpp Tue Dec 08 21:42:56 2015 +0000 @@ -0,0 +1,161 @@ +#include "mbed.h" +#include "iteadstudio_colourshield.h" +/**************Define*************************/ +DigitalOut RGB_RST(A2); +DigitalOut RGB_LAT(A1); +DigitalOut RGB_SB(A0); + +/*DigitalIn nn0(D7); +DigitalIn nn1(D2); +DigitalIn nn2(D6);*/ +SPI RGB_SPI(PB_15,PB_14,PB_13); +BusOut RGB_CP(D8,D9,D10,D11,D12,D13,D3,D4); +uint8_t RGBi= 0,RGBj= 0,RGBk= 0; +uint8_t RedWB=55,GreenWB=0,BlueWB=60; // percent | R,G,B calibrate change it if some color brighter than other +uint8_t display[8][8][3]= {0}; +/*******************************************/ +void sendframe(uint8_t frame[8][8][3]) +{ + memcpy(display, frame, sizeof(display)); +} +void INITRGB(char in[3]) +{ + int wd; + RGB_RST =0; + RGB_RST =1; + RGB_SPI.frequency(20000000); + RGB_SPI.format(8,1); + RGB_LAT = 0; + RGB_SB =0; + int l=0; + + for (int i = 0; i<8; i++) { // Whitebalance......**important + for (int j = 0; j<3; j++) { + for (int k = 0; k<6; k++) { + wd+=((in[j]<<k)&0b00100000)?1:0; + wd<<1; + l++; + if(l>=7) { + RGB_SPI.write(255); + l=0; + } + } + //RGB_SPI.write(255); + } + } + + RGB_LAT = 1; + RGB_LAT = 0; + + RGB_SPI.format(8,0); +} + +void displayRGB() +{ + + RGB_SB =1; + for( RGBi=0; RGBi<8; RGBi++) { + for( RGBk=0; RGBk<8; RGBk++) { + for( RGBj=0; RGBj<3; RGBj++) { + RGB_SPI.write(display[RGBk][RGBi][RGBj]); + } + + } + RGB_CP = 0; + wait_us(15); + RGB_LAT = 1; + RGB_LAT = 0; + + RGB_CP = (0x01<<RGBi); + + } +} + +void HSVtoRGB( float *r, float *g, float *b, float h, float s, float v ) +{ + int i; + float f, p, q, t; + if( s == 0 ) { + // achromatic (grey) + *r = *g = *b = v; + return; + } + h /= 60; // sector 0 to 5 + i = floor( h ); + f = h - i; // factorial part of h + p = v * ( 1 - s ); + q = v * ( 1 - s * f ); + t = v * ( 1 - s * ( 1 - f ) ); + switch( i ) { + case 0: + *r = v; + *g = t; + *b = p; + break; + case 1: + *r = q; + *g = v; + *b = p; + break; + case 2: + *r = p; + *g = v; + *b = t; + break; + case 3: + *r = p; + *g = q; + *b = v; + break; + case 4: + *r = t; + *g = p; + *b = v; + break; + default: // case 5: + *r = v; + *g = p; + *b = q; + break; + } +} +void screen_zeros() +{ + memset(display, 0, sizeof(display)); +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff -r 000000000000 -r 0def0023f900 iteadstudio_colourshield.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/iteadstudio_colourshield.h Tue Dec 08 21:42:56 2015 +0000 @@ -0,0 +1,11 @@ + +#ifndef iteadstudio_colourshield_H +#define iteadstudio_colourshield_H + +void INITRGB(char in[3]); //whitebalance define +void displayRGB(); //display +void HSVtoRGB( float *r, float *g, float *b, float h, float s, float v ); +void screen_zeros(); +void sendframe(uint8_t frame[8][8][3]); + +#endif // my8x8RGB_H \ No newline at end of file
diff -r 000000000000 -r 0def0023f900 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Dec 08 21:42:56 2015 +0000 @@ -0,0 +1,249 @@ +#include "mbed.h" +#include "iteadstudio_colourshield.h" +uint8_t frame[8][8][3]= {0}; +char mode = '1'; +char read = '0'; +char readon,readi,readj; +char trig = '0'; +char trigkey; +uint8_t keyarray[4][4] = {{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}}; +DigitalIn usrin(PC_13); +inline void midicon_display(uint8_t array[4][4],uint8_t BGR_col_map[4][4][3]); +inline void midi_rythm_display(uint8_t BGR_col_map88[8][8][3]); +Serial master(PA_11,PA_12); +Serial pc(USBTX, USBRX); +Timer timer; +Timer timer2; +int scount; + + +int begin; +void callback() +{ + // Note: you need to actually read from the serial to clear the RX interrupt + if(pc.getc()=='#') { + mode = pc.getc(); + pc.putc(mode); + } +} +void callbackmaster() +{ + // Note: you need to actually read from the serial to clear the RX interrupt + read =master.getc(); + if(read=='#') { + mode = master.getc(); + pc.putc(mode); + } else if(read == '$') { + //pc.putc(read); + readon = master.getc(); + //pc.putc(readon); + readi=master.getc(); + //pc.putc(readi); + readj=master.getc(); + //pc.putc(readj); + //pc.putc('\n'); + if(readon=='1') { + keyarray[3-(readj-'0')][(readi-'0')] =1; + } + if(readon=='0') { + //pc.putc('X'); + keyarray[3-(readj-'0')][readi-'0'] = 0; + } + } else if(read == '*') { + trig ='1'; + pc.putc('!'); + trigkey = master.getc(); + pc.putc(trigkey); + pc.putc('\n'); + } else { + pc.putc('-'); + pc.putc(read); + pc.putc('-'); + pc.putc('\n'); + } +} +int main() +{ + timer.start(); + pc.baud(115200); + pc.attach(&callback); + master.baud(115200); + master.attach(&callbackmaster); + + char wb[3]= {100,100,100}; + INITRGB(wb); + float r,g,b; + //float HSV[3]; + + while(1) { + if(mode=='0') { + for(int i =0; i<8; i++) { + for(int j= 0; j<8; j++) { + HSVtoRGB(&r,&g,&b,i*j*360/49,1,1); + frame[i][j][0]=(uint8_t)(b*230); + frame[i][j][1]=(uint8_t)(g*255); + frame[i][j][2]=(uint8_t)(r*155); + + } + } + while(mode == '0') { + sendframe(frame); + displayRGB(); + + + } + } + if(mode=='1') { + //rainbow keymap + + uint8_t bgr_col_map[4][4][3]; + + int key = 0; + for(int i=0 ; i<4; i++) { + for(int j=0 ; j<4; j++) { + HSVtoRGB(&r,&g,&b,key*360/15,1,1); + bgr_col_map[j][i][0] = (uint8_t)(b*230); + bgr_col_map[j][i][1] = (uint8_t)(g*255); + bgr_col_map[j][i][2] = (uint8_t)(r*155); + key++; + } + } + + while(mode == '1') { + midicon_display(keyarray,bgr_col_map); + } + + } else if(mode=='2') { + uint8_t rythm_col_map[8][8][3]; + //first col + for(int i = 0; i<2; i++) { + for(int j =0; j<6; j++) { + HSVtoRGB(&r,&g,&b,0,0,1); + rythm_col_map[i][j][0]=(uint8_t)(b*230); + rythm_col_map[i][j][1]=(uint8_t)(g*255); + rythm_col_map[i][j][2]=(uint8_t)(r*155); + } + } + //second col + for(int i = 2; i<4; i++) { + for(int j =0; j<6; j++) { + HSVtoRGB(&r,&g,&b,0,0,1); + rythm_col_map[i][j][0]=(uint8_t)(b*230); + rythm_col_map[i][j][1]=(uint8_t)(g*255); + rythm_col_map[i][j][2]=(uint8_t)(r*155); + } + } + //third col + for(int i = 4; i<6; i++) { + for(int j =0; j<6; j++) { + HSVtoRGB(&r,&g,&b,0,0,1); + rythm_col_map[i][j][0]=(uint8_t)(b*230); + rythm_col_map[i][j][1]=(uint8_t)(g*255); + rythm_col_map[i][j][2]=(uint8_t)(r*155); + } + } + //last col + for(int i = 6; i<8; i++) { + for(int j =0; j<6; j++) { + HSVtoRGB(&r,&g,&b,0,0,1); + rythm_col_map[i][j][0]=(uint8_t)(b*230); + rythm_col_map[i][j][1]=(uint8_t)(g*255); + rythm_col_map[i][j][2]=(uint8_t)(r*155); + } + } + //allbutton + for(int i = 0; i<8; i++) { + for(int j =6; j<8; j++) { + HSVtoRGB(&r,&g,&b,0,0,1); + rythm_col_map[i][j][0]=(uint8_t)(b*230); + rythm_col_map[i][j][1]=(uint8_t)(g*255); + rythm_col_map[i][j][2]=(uint8_t)(r*155); + } + } + + uint8_t canvas[8][8][3]; + //int velocity_ms = 100; + uint8_t padobject[4][6][2] = {0}; //col,maxnumber of obj,avalibility,pos + int i2; + memcpy(canvas,rythm_col_map,sizeof(canvas)); + while(mode == '2') { + + + + + if(trig=='1') { + memcpy(canvas,rythm_col_map,sizeof(canvas)); + trig='0'; + for(int i = 0 ; i<6; i++) { + if(trigkey-'0'!=0) + if(padobject[trigkey-'0'-1][i][0]==0) { + padobject[trigkey-'0'-1][i][0]=1; + break; + } + } + for(int i =0; i<4; i++) { + for(int j= 0; j<6; j++) { + if(padobject[i][j][0]==1) { + if(padobject[i][j][1]>5) { + padobject[i][j][0] = 0; + padobject[i][j][1] = 0; + } else { + //pc.putc('#'); + i2 = i*2; + canvas[i2][padobject[i][j][1]][0]=(uint8_t)(230); + canvas[i2][padobject[i][j][1]][1]=(uint8_t)(204); + canvas[i2][padobject[i][j][1]][2]=(uint8_t)(0); + canvas[i2+1][padobject[i][j][1]][0]=(uint8_t)(230); + canvas[i2+1][padobject[i][j][1]][1]=(uint8_t)(204); + canvas[i2+1][padobject[i][j][1]][2]=(uint8_t)(0); + padobject[i][j][1]++; + } + } + } + } + } + sendframe(canvas); + displayRGB(); + } + } + } +} +inline void midicon_display(uint8_t array[4][4],uint8_t BGR_col_map44[4][4][3]) +{ + uint8_t frameX[8][8][3]= {0}; + //memset(frameX,30,sizeof(frameX)); + //memcpy(frameX,BGR_bac_map88,sizeof(frameX)); + int n_x,n_y; + for( int x=0; x<4; x++) { + for( int y=0; y<4; y++) { + if(array[x][y]==1) { + + + n_x = x*2; + n_y = y*2; + frameX[n_x][n_y][0] = BGR_col_map44[x][y][0]; + frameX[n_x][n_y][1] = BGR_col_map44[x][y][1]; + frameX[n_x][n_y][2] = BGR_col_map44[x][y][2]; + + frameX[n_x+1][n_y][0] = BGR_col_map44[x][y][0]; + frameX[n_x+1][n_y][1] = BGR_col_map44[x][y][1]; + frameX[n_x+1][n_y][2] = BGR_col_map44[x][y][2]; + + frameX[n_x][n_y+1][0] = BGR_col_map44[x][y][0]; + frameX[n_x][n_y+1][1] = BGR_col_map44[x][y][1]; + frameX[n_x][n_y+1][2] = BGR_col_map44[x][y][2]; + + frameX[n_x+1][n_y+1][0] = BGR_col_map44[x][y][0]; + frameX[n_x+1][n_y+1][1] = BGR_col_map44[x][y][1]; + frameX[n_x+1][n_y+1][2] = BGR_col_map44[x][y][2]; + + + + } + } + } + sendframe(frameX); + displayRGB(); +} + +
diff -r 000000000000 -r 0def0023f900 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Dec 08 21:42:56 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/165afa46840b \ No newline at end of file
diff -r 000000000000 -r 0def0023f900 midirythm.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/midirythm.h Tue Dec 08 21:42:56 2015 +0000 @@ -0,0 +1,11 @@ + +#ifndef midirythm_H +#define midirythm_H + +void INITRGB(char in[3]); //whitebalance define +void displayRGB(); //display +void HSVtoRGB( float *r, float *g, float *b, float h, float s, float v ); +void screen_zeros(); +void sendframe(uint8_t frame[8][8][3]); + +#endif // my8x8RGB_H \ No newline at end of file
diff -r 000000000000 -r 0def0023f900 peach.cpp