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.
main.cpp
00001 #include "mbed.h" 00002 #include "VL6180X.h" 00003 #include "STMPE1600.h" 00004 #include "Display.h" 00005 #include "Switch.h" 00006 00007 00008 00009 00010 00011 00012 #ifdef TEST_LCD 00013 LCD tft(LCD_SPI_CS,LCD_SPI_DC, LCD_MOSI_PIN, LCD_MISO_PIN, LCD_SPI_CL_PIN,LCD_BL_PIN); 00014 #else 00015 #define LCD int 00016 LCD tft; 00017 #endif 00018 00019 00020 #if __TT_M3HQ__ 00021 #define DISPLAY_TMPM_STRING "Welcome to Thundersoft TT_M3HQ" 00022 #endif 00023 00024 00025 #if __TT_M4G9__ 00026 #define DISPLAY_TMPM_STRING "Welcome to Thundersoft TT_M4G9" 00027 #endif 00028 00029 00030 00031 00032 #define DISPLAY_VL6180_ID_STRING "VL6180 ID:" 00033 #define DISPLAY_VL6180_ID_HIGH (16 * 1) 00034 #define DISPLAY_STEMPE_STRING "STMPE ID:" 00035 #define DISPLAY_STEMPE_ID_HIGH (DISPLAY_VL6180_ID_HIGH * 2) 00036 #define DISPLAY_VL6180_RANGE_VALUE_STRING "VL6180X RANG:" 00037 #define DISPLAY_VL6180_RANGE_STRING_HIGH (DISPLAY_VL6180_ID_HIGH * 3) 00038 #define DISPLAY_VL6180_RANGE_VALUE_HIGH (DISPLAY_VL6180_ID_HIGH * 4) 00039 #define DISPLAY_VL6180_ALS_VALUE_STRING "VL6180X ALS:" 00040 #define DISPLAY_VL6180_ALS_STRING_HIGH (DISPLAY_VL6180_ID_HIGH * 5) 00041 #define DISPLAY_VL6180_ALS_VALUE_HIGH (DISPLAY_VL6180_ID_HIGH * 6) 00042 00043 00044 00045 00046 static void displayForVL6180X(LCD &lcd,VL6180X &vl6180x,STMPE1600 &stmpe1600) 00047 { 00048 #ifdef TEST_LCD 00049 char temp_buffer[5]; 00050 temp_buffer[4] = '\0'; 00051 lcd.drawString(0,0,DISPLAY_TMPM_STRING,RED); 00052 00053 lcd.drawString(0,DISPLAY_VL6180_ID_HIGH,DISPLAY_VL6180_ID_STRING,RED); 00054 translateBinaryToBCD(temp_buffer,vl6180x.readID()); 00055 lcd.drawString((sizeof(DISPLAY_VL6180_ID_STRING) - 1) * FONT_CHAR_WIDTH,DISPLAY_VL6180_ID_HIGH,(const char *)temp_buffer,BLACK); 00056 00057 displayId(lcd,DISPLAY_STEMPE_STRING,sizeof(DISPLAY_STEMPE_STRING),DISPLAY_STEMPE_ID_HIGH,stmpe1600.readID()); 00058 00059 /*Set 6180XA1 for LCD string*/ 00060 lcd.drawString(0,DISPLAY_VL6180_RANGE_STRING_HIGH,DISPLAY_VL6180_RANGE_VALUE_STRING,RED); 00061 lcd.drawString(0,DISPLAY_VL6180_ALS_STRING_HIGH,DISPLAY_VL6180_ALS_VALUE_STRING,RED); 00062 #endif 00063 } 00064 00065 static void handleLCDForVL6180X(LCD &lcd,VL6180X &vl6180x) 00066 { 00067 char temp_buffer[50]; 00068 while(1) 00069 { 00070 /*data for range */ 00071 memset(temp_buffer,0,sizeof(temp_buffer)); 00072 sprintf(temp_buffer,"%d",vl6180x.readRangeSingle()); 00073 #ifdef TEST_LCD 00074 lcd.drawString(0,DISPLAY_VL6180_RANGE_VALUE_HIGH,temp_buffer,RED); 00075 #endif 00076 printf("Range = %d \r\n",vl6180x.readRangeSingle()); 00077 /*data for als*/ 00078 memset(temp_buffer,0,sizeof(temp_buffer)); 00079 sprintf(temp_buffer,"%d",vl6180x.readAmbientSingle()); 00080 #ifdef TEST_LCD 00081 lcd.drawString(0,DISPLAY_VL6180_ALS_VALUE_HIGH,temp_buffer,RED); 00082 #endif 00083 printf("ALS = %d \r\n",vl6180x.readAmbientSingle()); 00084 wait_ms(1000); 00085 #ifdef TEST_LCD 00086 lcd.clearScreenArea(0,DISPLAY_VL6180_RANGE_VALUE_HIGH,WHITE); 00087 lcd.clearScreenArea(0,DISPLAY_VL6180_ALS_VALUE_HIGH,WHITE); 00088 #endif 00089 } 00090 } 00091 00092 00093 int main() 00094 { 00095 printf("%s\r\n",DISPLAY_TMPM_STRING); 00096 I2C *i2c =new I2C(D14,D15); 00097 VL6180X *vl6180x = new VL6180X(i2c); 00098 STMPE1600 *stmpe1600 = new STMPE1600(i2c); 00099 Display display(*stmpe1600); 00100 Switch _switch(*stmpe1600); 00101 //MeasureData_t measure_data; 00102 vl6180x->init(); 00103 vl6180x->configureDefault(); 00104 //vl6180x->startAmbientContinuous(); 00105 printf("Vl6180X ID = 0x%x \r\n",vl6180x->readID()); 00106 printf("STMPE1600 ID = 0x%x \r\n",stmpe1600->readID()); 00107 #ifdef TEST_LCD 00108 tft.init(); 00109 #endif 00110 displayForVL6180X(tft,*vl6180x,*stmpe1600); 00111 handleLCDForVL6180X(tft,*vl6180x); 00112 while(1) 00113 { 00114 } 00115 }
Generated on Tue Jul 12 2022 21:49:23 by
