Allans code

Dependencies:   RPG SerLCDv25 CascadedTLC5940 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "TLC5940.h"
00003 #include "SerLCDv25.h"
00004 #include "RPG.h"
00005 
00006 SPI spi (p5, NC, p7);//pin5 is sin/ nc/p7 is sclk
00007 DigitalOut dcprg (p6);//see p10
00008 DigitalOut xlat (p8);
00009 DigitalOut blank (p9);
00010 DigitalOut vprg (p10);//this might need to be swapped with dcprg cause pins may be backwards
00011  
00012 SPI adcspi (NC, p12, p13);//adc
00013 DigitalOut cs(p14);//chipselect
00014 PwmOut gsclk (p21);//constantly gives clock to grey scale clock
00015 Serial lcdspi(p28, NC);//do not need pin 27 
00016 //Constructor(Channel A input pin, Channel B input pin, Pushbutton input pin)
00017 RPG encoder1 (p27,p29,p30);//encoder top left 
00018 RPG encoder2 (p26,p25,p24);//encoder middle right
00019 //RPG encoder3 (p22,p23,p11);//Left connected to check batterylevels
00020 AnalogIn vbatt(p20);//analog input span of 0 to check for battery levels
00021 InterruptIn interpulsea(p22);
00022 InterruptIn interpulseb(p23);
00023 InterruptIn inter(p11);//pb interrupt
00024 
00025 DigitalOut led1(LED1);
00026 DigitalOut led2(LED2);
00027 DigitalOut led3(LED3);
00028 DigitalOut led4(LED4);
00029 
00030 
00031 int ic_number = 3; //change depending on ics you have
00032 unsigned short leds [48];//number of channels you will have 16*number of ics
00033 
00034 BusOut mux(p15, p16, p17, p18);
00035 //A0
00036 //mux
00037 //mux
00038 //a3
00039 DigitalOut muxenable(p19);
00040 //EN
00041 void startup(void);
00042 void checkbattery(void);
00043 void ledstartup(void);
00044 void ledtest(void);
00045 
00046 
00047 
00048 
00049 int main() //main start function =============================================================<<<<<<<<<<<<<<<<<<<<<<<<<
00050 {
00051 
00052     startup();
00053     setup (spi, vprg, xlat, blank, dcprg, gsclk, ic_number);//setsup led
00054     ledstartup();//test all leds in sequence 0-15 in R then G then B 
00055     //padpush(15,0xf0,0x0f,0x01);
00056     led1 =0;
00057     led2 =0;
00058     led3 =0;
00059     led4 =0;
00060     inter.fall(&ledstartup);
00061     interpulsea.fall(&ledtest);
00062     interpulseb.fall(&ledtest);
00063     while(1) // MAIN LOOOP ====================================================================<<<<<<<<<<<<<<<<<<<
00064     {
00065       muxenable = 1;
00066       for (int m = 0; m <=0xf; m++)
00067       {
00068         mux = m;
00069         //if adc > something do something
00070       }
00071       padpush(0x0,0x10,0xff,0x01);
00072       led4=!led4;
00073       update_led (spi, xlat, blank, (unsigned short*)leds);
00074       
00075     
00076 
00077    // update_led (spi, xlat, blank, (unsigned short*)leds);
00078 
00079     }//endofwhile
00080 }//endofmain
00081 
00082 
00083 
00084 
00085 
00086 
00087 
00088 
00089 
00090 
00091 //LCD FUNCTIONS================================================================================
00092 
00093 void clear(void) {//clear lcd display
00094     lcdspi.putc(0xFE);
00095     lcdspi.putc(0x01);
00096 }
00097  
00098 
00099 void move_cursor(int line, int pos) {//move to a certain part of the lcd
00100     int cp;
00101     cp = pos + (line * 64) +128;
00102     lcdspi.putc(0xFE);
00103     lcdspi.putc(cp);
00104 }
00105 
00106 
00107 
00108 //Allan's Functions ===================================================================
00109 void startup(void)
00110 {
00111     for (int a = 0; a<3;a++)
00112     {
00113         clear();
00114         move_cursor(0,0);
00115         lcdspi.printf("Initializing");
00116         wait(0.2);
00117         lcdspi.printf(".");
00118         wait(0.2);      
00119         lcdspi.printf(".");
00120         wait(0.2);
00121         lcdspi.printf(".");
00122         wait(0.2);
00123     }    
00124     checkbattery();//in initialize, check battery levels
00125 }
00126 
00127 void checkbattery(void)
00128 {
00129     float batterylevel = vbatt*100;
00130     
00131     //Check Battery Levels
00132         led1 = (vbatt > 0.2) ? 1 : 0;
00133         led2 = (vbatt > 0.4) ? 1 : 0;
00134         led3 = (vbatt > 0.6) ? 1 : 0;
00135         led4 = (vbatt > 0.8) ? 1 : 0;
00136         if (vbatt< 0.2) {
00137             clear();
00138             move_cursor(0,0);
00139             lcdspi.printf("WARNING");
00140             move_cursor(1,0);
00141             lcdspi.printf("LOW BATTERY");
00142             wait(2);}
00143         else 
00144         {
00145             clear();
00146             move_cursor(0,0);
00147             lcdspi.printf("Battery Level");
00148             move_cursor(1,0);
00149             lcdspi.printf("      %.0f%%",batterylevel);}
00150             wait(2);
00151     
00152 }
00153 //CheckallLEDS on startup
00154 void ledstartup(void)
00155 {
00156     clear();
00157     move_cursor(0,0);
00158     lcdspi.printf("LED TEST");
00159     for (int t = 0; t<=48;t++) //will check all leds and colors R G B to ensure there are no shorts
00160     {
00161         clearall();
00162         leds[t] = 0xff;
00163         update_led (spi, xlat, blank, (unsigned short*)leds);
00164         wait(0.02);
00165         
00166     }
00167     clear();
00168 }
00169 
00170 void ledtest(void)
00171 {
00172     
00173 }
00174 
00175 
00176 //TLC5940 Pushbutton Functions============================================
00177 //Writes to 1 button and allows you to control 3 colours
00178 //k = 0-15 indicates which button you want to select
00179 //r g b = value between 0x0-0xff. 0xff = full brightness
00180 void padpush (int k,int r,int g,int b)
00181 {
00182     //k=0x1-0xfff    
00183     leds[k] = r;
00184     leds[k+16] = g;
00185     leds[k+32] = b;
00186 }
00187 //Turn all LEDS on pads off
00188 void clearall(void)
00189 {
00190     for (int i = 0; i<=(ic_number*16-1);i++)
00191     {
00192          leds [i] =0;
00193     }
00194 }