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
iteadstudio_colourshield.cpp
00001 #include "mbed.h" 00002 #include "iteadstudio_colourshield.h" 00003 /**************Define*************************/ 00004 DigitalOut RGB_RST(A2); 00005 DigitalOut RGB_LAT(A1); 00006 DigitalOut RGB_SB(A0); 00007 00008 /*DigitalIn nn0(D7); 00009 DigitalIn nn1(D2); 00010 DigitalIn nn2(D6);*/ 00011 SPI RGB_SPI(PB_15,PB_14,PB_13); 00012 BusOut RGB_CP(D8,D9,D10,D11,D12,D13,D3,D4); 00013 uint8_t RGBi= 0,RGBj= 0,RGBk= 0; 00014 uint8_t RedWB=55,GreenWB=0,BlueWB=60; // percent | R,G,B calibrate change it if some color brighter than other 00015 uint8_t display[8][8][3]= {0}; 00016 /*******************************************/ 00017 void sendframe(uint8_t frame[8][8][3]) 00018 { 00019 memcpy(display, frame, sizeof(display)); 00020 } 00021 void INITRGB(char in[3]) 00022 { 00023 int wd; 00024 RGB_RST =0; 00025 RGB_RST =1; 00026 RGB_SPI.frequency(20000000); 00027 RGB_SPI.format(8,1); 00028 RGB_LAT = 0; 00029 RGB_SB =0; 00030 int l=0; 00031 00032 for (int i = 0; i<8; i++) { // Whitebalance......**important 00033 for (int j = 0; j<3; j++) { 00034 for (int k = 0; k<6; k++) { 00035 wd+=((in[j]<<k)&0b00100000)?1:0; 00036 wd<<1; 00037 l++; 00038 if(l>=7) { 00039 RGB_SPI.write(255); 00040 l=0; 00041 } 00042 } 00043 //RGB_SPI.write(255); 00044 } 00045 } 00046 00047 RGB_LAT = 1; 00048 RGB_LAT = 0; 00049 00050 RGB_SPI.format(8,0); 00051 } 00052 00053 void displayRGB() 00054 { 00055 00056 RGB_SB =1; 00057 for( RGBi=0; RGBi<8; RGBi++) { 00058 for( RGBk=0; RGBk<8; RGBk++) { 00059 for( RGBj=0; RGBj<3; RGBj++) { 00060 RGB_SPI.write(display[RGBk][RGBi][RGBj]); 00061 } 00062 00063 } 00064 RGB_CP = 0; 00065 wait_us(15); 00066 RGB_LAT = 1; 00067 RGB_LAT = 0; 00068 00069 RGB_CP = (0x01<<RGBi); 00070 00071 } 00072 } 00073 00074 void HSVtoRGB( float *r, float *g, float *b, float h, float s, float v ) 00075 { 00076 int i; 00077 float f, p, q, t; 00078 if( s == 0 ) { 00079 // achromatic (grey) 00080 *r = *g = *b = v; 00081 return; 00082 } 00083 h /= 60; // sector 0 to 5 00084 i = floor( h ); 00085 f = h - i; // factorial part of h 00086 p = v * ( 1 - s ); 00087 q = v * ( 1 - s * f ); 00088 t = v * ( 1 - s * ( 1 - f ) ); 00089 switch( i ) { 00090 case 0: 00091 *r = v; 00092 *g = t; 00093 *b = p; 00094 break; 00095 case 1: 00096 *r = q; 00097 *g = v; 00098 *b = p; 00099 break; 00100 case 2: 00101 *r = p; 00102 *g = v; 00103 *b = t; 00104 break; 00105 case 3: 00106 *r = p; 00107 *g = q; 00108 *b = v; 00109 break; 00110 case 4: 00111 *r = t; 00112 *g = p; 00113 *b = v; 00114 break; 00115 default: // case 5: 00116 *r = v; 00117 *g = p; 00118 *b = q; 00119 break; 00120 } 00121 } 00122 void screen_zeros() 00123 { 00124 memset(display, 0, sizeof(display)); 00125 } 00126 00127 00128 00129 00130 00131 00132 00133 00134 00135 00136 00137 00138 00139 00140 00141 00142 00143 00144 00145 00146 00147 00148 00149 00150 00151 00152 00153 00154 00155 00156 00157 00158 00159 00160 00161
Generated on Sat Jul 23 2022 04:24:59 by
1.7.2