HexiWear Bubble level program
Dependencies: FXOS8700 NeatGUI
main.cpp
00001 #include "mbed.h" 00002 #include <SSD1351_SPI.h> 00003 #include <HexiBubble.h> 00004 #include "FXOS8700.h" 00005 00006 //SSD1351_SPI ( mosi, miso, sclk, cs, dc ) ; 00007 SSD1351_SPI OLED96x96(PTB22,PTB23,PTB21,PTB20,PTD15); 00008 // Pin connections for Hexiwear 00009 FXOS8700 accel(PTC11, PTC10); 00010 // Storage for the data from the sensor 00011 float accel_data[3]; float accel_rms=0.0; 00012 DigitalOut led1(LED1); 00013 DigitalOut led2(LED2); 00014 DigitalOut led3(LED3); 00015 DigitalOut BOOSTEN(PTC13); //oled power enable 00016 int count = 0; 00017 int count2 = 0; 00018 extern const uint8_t Main_screen_bmp[ 36864 ]; 00019 int argb = 0xff000000; 00020 int rgbd = 0x00000000; 00021 int xposg = 0; 00022 int yposg = 0; 00023 int main() { 00024 led1 = 1; 00025 led2 = 1; 00026 led3 = 1; 00027 // Configure Accelerometer FXOS8700 00028 accel.accel_config(); 00029 BOOSTEN = 1; 00030 OLED96x96.open(); 00031 OLED96x96.state(Display::DISPLAY_ON); 00032 OLED96x96.fillRect(16,0,111,96,0xff000000);//alpha, BGR 00033 for(int xpos=0;xpos<97;xpos++) 00034 { 00035 for(int ypos=0;ypos<96;ypos++) 00036 { 00037 rgbd = ((Main_screen_bmp[count+3]<<24)|(Main_screen_bmp[count]<<16)|(Main_screen_bmp[count+1]<<8)|(Main_screen_bmp[count+2])); 00038 OLED96x96.drawPixel(ypos+16,xpos,rgbd); 00039 count=count+4; 00040 } 00041 } 00042 OLED96x96.drawCircle(61,47,4,0xff00ff00); 00043 OLED96x96.drawCircle(61,47,3,0xff00ff00); 00044 OLED96x96.drawCircle(61,47,2,0xff00ff00); 00045 while(1) 00046 { 00047 accel.acquire_accel_data_g(accel_data); 00048 xposg=(accel_data[1]*(-40.0)); 00049 if (xposg > 27) 00050 xposg = 27; 00051 if (xposg < -27) 00052 xposg = -27; 00053 yposg=accel_data[0]*40.0; 00054 if (yposg > 27) 00055 yposg = 27; 00056 if (yposg < -27) 00057 yposg = -27; 00058 if((xposg == 0) and (yposg == 0)) 00059 { 00060 led1 = 1; 00061 led2 = 0; 00062 } 00063 OLED96x96.drawCircle(61,47,8,0xff00ff00); 00064 OLED96x96.drawLine(61,7,61,87,0xff00ff00); 00065 OLED96x96.drawLine(21,47,101,47,0xff00ff00); 00066 OLED96x96.drawCircle(61-xposg,47+yposg,4,0xff00ff00); 00067 OLED96x96.drawCircle(61-xposg,47+yposg,3,0xff00ff00); 00068 OLED96x96.drawCircle(61-xposg,47+yposg,2,0xff00ff00); 00069 Thread::wait(20); 00070 OLED96x96.drawCircle(61-xposg,47+yposg,4,0xff000000); 00071 OLED96x96.drawCircle(61-xposg,47+yposg,3,0xff000000); 00072 OLED96x96.drawCircle(61-xposg,47+yposg,2,0xff000000); 00073 led1 = 0; 00074 led2 = 1; 00075 count2++; 00076 if (count2 > 100) 00077 { //blank display to avoid image burn 00078 OLED96x96.fillRect(16,0,111,96,0xff000000);//alpha, BGR 00079 count2 = 0; 00080 } 00081 //BOOSTEN = 0; //turn off display after about 1 minute to avoid image burn 00082 } 00083 00084 } 00085
Generated on Sun Jul 17 2022 01:36:15 by 1.7.2