Gestion de la couleur du rétroéclairage de l'écran LCD avec un potentiomètre

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 I2C link(I2C_SDA, I2C_SCL);
00004 const int addr = 0x7C;
00005 
00006 void Init(void){
00007     char cmd[2];
00008     cmd[0] = 0x80;
00009     cmd[1] = 0x3C;
00010     link.write(addr,cmd,2);
00011     wait_us(100);
00012     
00013     cmd[1] = 0x0F;
00014     link.write(addr,cmd,2);
00015     wait_us(100);
00016     
00017     cmd[1] = 0x01;
00018     link.write(addr,cmd,2);
00019     wait_ms(2);
00020     
00021     cmd[1] = 0x06;
00022     link.write(addr,cmd,2);
00023     wait_us(100);
00024 }
00025 
00026 void initRGB(void){
00027     char cmd[2];
00028     
00029     cmd[0] = 0x00;
00030     cmd[1] = 0x00;
00031     link.write(0xC4,cmd,2);
00032     wait_us(100);
00033     
00034     cmd[0] = 0x01;
00035     cmd[1] = 0x00;
00036     link.write(0xC4,cmd,2);
00037     wait_us(100);
00038     
00039     cmd[0] = 0x08;
00040     cmd[1] = 0xAA;
00041     link.write(0xC4,cmd,2);
00042     wait_us(100);
00043 }
00044 
00045 void setup(char R,char G, char B){
00046     char cmd[2];
00047     
00048     cmd[0] = 0x02;
00049     cmd[1] = B;
00050     link.write(0xC4,cmd,2);
00051     wait_us(100);
00052     
00053     cmd[0] = 0x03;
00054     cmd[1] = G;
00055     link.write(0xC4,cmd,2);
00056     wait_us(100);
00057     
00058     cmd[0] = 0x04;
00059     cmd[1] = R;
00060     link.write(0xC4,cmd,2);
00061     wait_us(100);
00062 }
00063 
00064 
00065 int main(void){
00066     AnalogIn Pot(A0);
00067     
00068     char data[12];
00069     char R,G,B;
00070     
00071     Init();
00072     initRGB();
00073     
00074     data[0] = 0x40;
00075     data[1] = 'H';
00076     data[2] = 'e';
00077     data[3] = 'l';
00078     data[4] = 'l';
00079     data[5] = 'o';
00080     data[6] = ' ';
00081     data[7] = 'W';
00082     data[8] = 'o';
00083     data[9] = 'r';
00084     data[10] = 'l';
00085     data[11] = 'd';
00086     
00087     link.write(addr,data,12);
00088     
00089     while(1){
00090         if( (Pot>0.2f) & (Pot<=0.4f)){
00091             R = 0xFF;
00092             G = 0x00;
00093             B = 0x00;
00094         }else if( (Pot>0.4f) & (Pot<=0.6f) ){
00095             R = 0x00;
00096             G = 0xFF;
00097             B= 0x00;   
00098         }else if( (Pot>0.6f) ){
00099             R = 0x00;
00100             G = 0x00;
00101             B = 0xFF;
00102         }else{
00103             R = 0x00;
00104             G = 0x00;
00105             B = 0x00;
00106         }
00107         setup(R,G,B);
00108     }
00109 }