![](/media/cache/group/Thundersoft-new.png.50x50_q85.png)
Creating a project about A8491 for TT_Mxx
main.cpp@0:6fc4594bc1db, 2019-03-22 (annotated)
- Committer:
- ThunderSoft
- Date:
- Fri Mar 22 07:16:37 2019 +0000
- Revision:
- 0:6fc4594bc1db
- Child:
- 1:da8c10bb7386
Add code about A8491
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ThunderSoft | 0:6fc4594bc1db | 1 | /* mbed Microcontroller Library |
ThunderSoft | 0:6fc4594bc1db | 2 | * Copyright (c) 2018 ARM Limited |
ThunderSoft | 0:6fc4594bc1db | 3 | * SPDX-License-Identifier: Apache-2.0 |
ThunderSoft | 0:6fc4594bc1db | 4 | */ |
ThunderSoft | 0:6fc4594bc1db | 5 | |
ThunderSoft | 0:6fc4594bc1db | 6 | #include "mbed.h" |
ThunderSoft | 0:6fc4594bc1db | 7 | #include "MMA8491.h" |
ThunderSoft | 0:6fc4594bc1db | 8 | |
ThunderSoft | 0:6fc4594bc1db | 9 | |
ThunderSoft | 0:6fc4594bc1db | 10 | |
ThunderSoft | 0:6fc4594bc1db | 11 | #ifdef TEST_LCD |
ThunderSoft | 0:6fc4594bc1db | 12 | LCD tft(LCD_SPI_CS,LCD_SPI_DC, LCD_MOSI_PIN, LCD_MISO_PIN, LCD_SPI_CL_PIN,LCD_BL_PIN); |
ThunderSoft | 0:6fc4594bc1db | 13 | #else |
ThunderSoft | 0:6fc4594bc1db | 14 | #define LCD int |
ThunderSoft | 0:6fc4594bc1db | 15 | LCD tft; |
ThunderSoft | 0:6fc4594bc1db | 16 | #endif |
ThunderSoft | 0:6fc4594bc1db | 17 | |
ThunderSoft | 0:6fc4594bc1db | 18 | |
ThunderSoft | 0:6fc4594bc1db | 19 | #define DISPLAY_TMPM_STRING "Welcome to Thundersoft TT_M3HQ" |
ThunderSoft | 0:6fc4594bc1db | 20 | |
ThunderSoft | 0:6fc4594bc1db | 21 | /*macros for A8491 board*/ |
ThunderSoft | 0:6fc4594bc1db | 22 | #define DISPLAY_A8491_STRING "A8491 board:" |
ThunderSoft | 0:6fc4594bc1db | 23 | #define DISPLAY_A8491_STRING_HIGH 16 |
ThunderSoft | 0:6fc4594bc1db | 24 | #define DISPLAY_A8491_VALUE_STRING "A8491 value:" |
ThunderSoft | 0:6fc4594bc1db | 25 | #define DISPLAY_A8491_VALUE_STRING_HIGH 32 |
ThunderSoft | 0:6fc4594bc1db | 26 | #define DISPLAY_A8491_VALUE_HIGH 48 |
ThunderSoft | 0:6fc4594bc1db | 27 | |
ThunderSoft | 0:6fc4594bc1db | 28 | |
ThunderSoft | 0:6fc4594bc1db | 29 | |
ThunderSoft | 0:6fc4594bc1db | 30 | static void displayForA8491(LCD &lcd) |
ThunderSoft | 0:6fc4594bc1db | 31 | { |
ThunderSoft | 0:6fc4594bc1db | 32 | #ifdef TEST_LCD |
ThunderSoft | 0:6fc4594bc1db | 33 | lcd.drawString(0,0,DISPLAY_TMPM_STRING,RED); |
ThunderSoft | 0:6fc4594bc1db | 34 | lcd.drawString(0,DISPLAY_A8491_STRING_HIGH,DISPLAY_A8491_STRING,RED); |
ThunderSoft | 0:6fc4594bc1db | 35 | lcd.drawString(0,DISPLAY_A8491_VALUE_STRING_HIGH,DISPLAY_A8491_VALUE_STRING,RED); |
ThunderSoft | 0:6fc4594bc1db | 36 | #endif |
ThunderSoft | 0:6fc4594bc1db | 37 | } |
ThunderSoft | 0:6fc4594bc1db | 38 | |
ThunderSoft | 0:6fc4594bc1db | 39 | static void handleLCDForA8491(LCD &lcd,MMA8491 &accel) |
ThunderSoft | 0:6fc4594bc1db | 40 | { |
ThunderSoft | 0:6fc4594bc1db | 41 | float accel_data[3]; float accel_rms=0.0; |
ThunderSoft | 0:6fc4594bc1db | 42 | char temp_buffer[50]; |
ThunderSoft | 0:6fc4594bc1db | 43 | while(1) |
ThunderSoft | 0:6fc4594bc1db | 44 | { |
ThunderSoft | 0:6fc4594bc1db | 45 | #ifdef TEST_LCD |
ThunderSoft | 0:6fc4594bc1db | 46 | accel.acquire_MMA8491_data_g(accel_data); |
ThunderSoft | 0:6fc4594bc1db | 47 | sprintf(temp_buffer,"%4.2f,%4.2f,%4.2f",accel_data[0],accel_data[1],accel_data[2]); |
ThunderSoft | 0:6fc4594bc1db | 48 | lcd.drawString(0,DISPLAY_A8491_VALUE_HIGH,temp_buffer,RED); |
ThunderSoft | 0:6fc4594bc1db | 49 | #endif |
ThunderSoft | 0:6fc4594bc1db | 50 | printf("%4.2f,%4.2f,%4.2f,\r\n",accel_data[0],accel_data[1],accel_data[2]); |
ThunderSoft | 0:6fc4594bc1db | 51 | #ifdef TEST_LCD |
ThunderSoft | 0:6fc4594bc1db | 52 | wait_ms(1000); |
ThunderSoft | 0:6fc4594bc1db | 53 | lcd.clearScreenArea(0,DISPLAY_A8491_VALUE_HIGH,WHITE); |
ThunderSoft | 0:6fc4594bc1db | 54 | #endif |
ThunderSoft | 0:6fc4594bc1db | 55 | } |
ThunderSoft | 0:6fc4594bc1db | 56 | } |
ThunderSoft | 0:6fc4594bc1db | 57 | |
ThunderSoft | 0:6fc4594bc1db | 58 | |
ThunderSoft | 0:6fc4594bc1db | 59 | |
ThunderSoft | 0:6fc4594bc1db | 60 | int main() |
ThunderSoft | 0:6fc4594bc1db | 61 | { |
ThunderSoft | 0:6fc4594bc1db | 62 | MMA8491 accel(D14,D15,A1); |
ThunderSoft | 0:6fc4594bc1db | 63 | float accel_data[3]; float accel_rms=0.0; |
ThunderSoft | 0:6fc4594bc1db | 64 | #ifdef TEST_LCD |
ThunderSoft | 0:6fc4594bc1db | 65 | tft.init(); |
ThunderSoft | 0:6fc4594bc1db | 66 | displayForA8491(tft); |
ThunderSoft | 0:6fc4594bc1db | 67 | #endif |
ThunderSoft | 0:6fc4594bc1db | 68 | printf("%s\r\n",DISPLAY_TMPM_STRING); |
ThunderSoft | 0:6fc4594bc1db | 69 | handleLCDForA8491(tft,accel); |
ThunderSoft | 0:6fc4594bc1db | 70 | while(1) |
ThunderSoft | 0:6fc4594bc1db | 71 | { |
ThunderSoft | 0:6fc4594bc1db | 72 | } |
ThunderSoft | 0:6fc4594bc1db | 73 | } |