SmartGPU2 Hardware Objects Demo - MBED + SmartGPU2 board

Dependencies:   SMARTGPU2 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /**************************************************************************************/
00002 /**************************************************************************************/
00003 /*SMARTGPU2 intelligent embedded graphics processor unit
00004  those examples are for using the SMARTGPU2 with the mbed microcontoller, just connect tx,rx,and reset
00005  Board:
00006  http://www.vizictechnologies.com/
00007  
00008  www.vizictechnologies.com 
00009  Vizic Technologies copyright 2014 */
00010 /**************************************************************************************/
00011 /**************************************************************************************/
00012 
00013 #include "mbed.h"
00014 #include "SMARTGPU2.h"
00015 
00016 SMARTGPU2 lcd(TXPIN,RXPIN,RESETPIN);  //create our object called "lcd"
00017 
00018 
00019 /***************************************************/
00020 /***************************************************/
00021 void initializeSmartGPU2(void){      //Initialize SMARTGPU2 Board
00022   lcd.reset();                       //physically reset SMARTGPU2
00023   lcd.start();                       //initialize the SMARTGPU2 processor
00024 }
00025 
00026 /***************************************************/
00027 /***************************************************/
00028 /***************************************************/
00029 /***************************************************/
00030 int main() {
00031   POINT point;
00032   unsigned char progress=0;
00033   char sliderPosition=49, scrollPosition=4;
00034       
00035   initializeSmartGPU2();             //Init communication with SmartGPU2 board
00036   
00037   lcd.baudChange(BAUD6);             //set a fast baud! for fast drawing
00038   
00039 //DRAW INITIAL STATE/VALUES OBJECTS
00040   //draw the object window
00041   lcd.objWindow(0,0,MAX_X_LANDSCAPE,MAX_Y_LANDSCAPE, FONT1, SELECTEDGRAY, "objects window");
00042   //draw the object slider
00043   lcd.objSlider(10, 80, 309, 115, sliderPosition, 100, HORIZONTAL); //draw the slider  with 100 divisions and 49 as current position
00044   //draw the object scroll bar
00045   lcd.objScrollBar(10, 125, 309, 160, scrollPosition, 10, HORIZONTAL, DESELECTED); //draw the scroll bar with 10 divisions and 4 as current position
00046   //draw the object button1 and button2
00047   lcd.objButton(10, 170, 150, 220, DESELECTED, "button 1");
00048   lcd.objButton(170, 170, 309, 220, DESELECTED, "button 2");     
00049      
00050 //LOOP FOREVER AND DRAW ONLY IF TOUCH ON OBJECT     
00051   while(1){
00052     //draw the object progress bar - this is the only object that doesn't wait for a touch, it just updates automatically each delay cycle
00053     lcd.objProgressBar(10, 40, 309, 70, progress++); //draw the progress bar with the "progress" variable value
00054     if(progress>100) progress = 0;   
00055  
00056     //ask for a touch
00057     if(lcd.touchScreen(&point)==VALID){ //if a touch on screen is valid
00058       //IF SLIDER
00059       if(point.y>80 && point.y<115){ //if the touch on the slider
00060         sliderPosition = ((point.x*100)/(309-10)); //scale the value and set it to sliderPosition
00061         //draw the object slider with currently obtained scaled touch value
00062         lcd.objSlider(10, 80, 309, 115, sliderPosition, 100, HORIZONTAL); //draw the slider  with 100 divisions and "sliderPosition" variable value                  
00063       }
00064       //IF SCROLLBAR        
00065       if(point.y>125 && point.y<160){ //if the touch on the scroll bar
00066         if(point.x>(MAX_X_LANDSCAPE-SCROLLBUTTONSIZE)){ //if touch is on the right > button
00067           scrollPosition++;          
00068           if(scrollPosition>9) scrollPosition=9;              
00069           //draw the object scroll bar as SELECTED
00070           lcd.objScrollBar(10, 125, 309, 160, scrollPosition, 10, HORIZONTAL, SELECTED); //draw the scroll bar with 10 divisions and "scrollPosition" variable value                      
00071         }else if(point.x<SCROLLBUTTONSIZE){             //if touch is on the left < button
00072           scrollPosition--;  
00073           if(scrollPosition<0) scrollPosition=0;
00074           //draw the object scroll bar as SELECTED
00075           lcd.objScrollBar(10, 125, 309, 160, scrollPosition, 10, HORIZONTAL, SELECTED); //draw the scroll bar with 10 divisions and "scrollPosition" variable value    
00076         }
00077         wait_ms(50);
00078         lcd.objScrollBar(10, 125, 309, 160, scrollPosition, 10, HORIZONTAL, DESELECTED); //draw the scroll bar with 10 divisions and "scrollPosition" variable value        
00079       }
00080       //IF BUTTON1        
00081       if(point.y>170 && point.y<220 && point.x<160){ //if the touch on button1
00082         //draw the object button1 as SELECTED
00083         lcd.objButton(10, 170, 150, 220, SELECTED, "button 1");
00084         wait_ms(50);
00085         lcd.objButton(10, 170, 150, 220, DESELECTED, "button 1");
00086       }
00087       //IF BUTTON2        
00088       if(point.y>170 && point.y<220 && point.x>160){ //if the touch on button2
00089         //draw the object button2 as SELECTED
00090         lcd.objButton(170, 170, 309, 220, SELECTED, "button 2");
00091         wait_ms(50);
00092         lcd.objButton(170, 170, 309, 220, DESELECTED, "button 2");
00093       }
00094     }
00095     //update objects each 100 milliseconds
00096     wait_ms(100);      
00097   }
00098 }