![](/media/cache/group/ON-Semiconductor.jpg.50x50_q85.jpg)
mbed example application for the Adafruit ST7735 TFT Shield, which implements SPI connections to the TFT shield and SD card, as well as an ADC to read from the analog in pins.
Dependencies: Adafruit_GFX Adafruit_ST7735 SDFileSystem mbed-os
Fork of mbed-TFT-example-NCS36510 by
Revision 3:81a34c232d99, committed 2017-02-27
- Comitter:
- jacobjohnson
- Date:
- Mon Feb 27 17:49:04 2017 +0000
- Parent:
- 2:fa3fb1787cf8
- Commit message:
- Working mbed-TFT example. functionality for TFT screen, reading a 24 bit BMP from the SD card, logging data files to SD card, and reading the analog in Joystick. This revision depends on the inputscale factor for ADC to be 7. Future change in main
Changed in this revision
--- a/Adafruit_GFX.lib Tue Jan 31 17:16:30 2017 +0000 +++ b/Adafruit_GFX.lib Mon Feb 27 17:49:04 2017 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/nkhorman/code/Adafruit_GFX/#7fb1d4d3525d +https://developer.mbed.org/teams/onsemi/code/Adafruit_GFX/#7fb1d4d3525d
--- a/Adafruit_ST7735.lib Tue Jan 31 17:16:30 2017 +0000 +++ b/Adafruit_ST7735.lib Mon Feb 27 17:49:04 2017 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/users/jacobjohnson/code/Adafruit_ST7735/#5842518d1feb +https://developer.mbed.org/teams/onsemi/code/Adafruit_ST7735/#196b625fe857
--- a/SDFileSystem.lib Tue Jan 31 17:16:30 2017 +0000 +++ b/SDFileSystem.lib Mon Feb 27 17:49:04 2017 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/mbed/code/SDFileSystem/#8db0d3b02cec +https://developer.mbed.org/teams/onsemi/code/SDFileSystem/#8db0d3b02cec
--- a/main.cpp Tue Jan 31 17:16:30 2017 +0000 +++ b/main.cpp Mon Feb 27 17:49:04 2017 +0000 @@ -1,41 +1,69 @@ /*************************************** -This is a working copy. It is not finished. +Example Application for the Adafruit ST7735 TFT Shield +on the ON Semiconductor NCS36510 mbed Board ***************************************/ #include "mbed.h" #include "Adafruit_ST7735.h" #include "SDFileSystem.h" -//#include <string> +#include <string> +#include <sstream> + +using namespace std; + DigitalOut led1(LED1); +AnalogIn adc_in_3(A3); +AnalogIn adc_in_2(A2); + SDFileSystem sd(D11, D12, D13, D4, "SD"); // the pinout on the mbed // mosi, miso, sclk, cs Adafruit_ST7735 tft(D11, D12, D13, D10, D6, D9); // MOSI, MISO, SCLK, SSEL, TFT_DC, TFT_RST -AnalogIn joystick(A3); -uint8_t readButton(void); +Serial PC(USBTX, USBRX); + -// main() runs in its own thread in the OS -// (note the calls to wait below for delays) int main() { - + PC.printf("start"); + tft.initR(INITR_BLACKTAB); // initialize a ST7735S chip, black tab tft.fillScreen(ST7735_BLACK); + tft.DrawBitmapFile("/SD/ON.bmp"); //Note, this must be a 24-bit Bitmap file, with a resolution less than 128x160 pixels - int result = tft.DrawBitmapFile("/SD/ON.bmp"); - + float a, b; + uint32_t file_index = 0; + while (true) { - float b = joystick.read(); + stringstream temp_str; + temp_str<<(file_index); + string filename_str = "/SD/data" + temp_str.str() + ".csv"; + const char* filename_cstr = filename_str.c_str(); + FILE *fp = fopen(filename_cstr, "w"); + led1=1; + - tft.setTextColor(ST7735_GREEN); - //tft.setCursor(0, 60); //claims that this is not in the Adafruit_ST7735 library? How are these files linked together? - tft.printf("%f \n\r", b); - printf("%f \n\r", b); - wait_ms(100); - + uint32_t i = 0; + while (i < 50){ + a = adc_in_3.read(); /* Read the converted analog value */ + b = adc_in_2.read(); + fprintf(fp,"%f\n", a); + tft.setTextColor(ST7735_GREEN, ST7735_BLACK); //(Text Color, Background color) + tft.setTextCursor(0, 120); + tft.printf("ADC 3: %f\n\rADC 2: %f\n\r", (a), (b)); + if (a < 0.1){tft.printf("Joystick: LEFT ");} + else if (a > 0.1 && a < .2){tft.printf("Joystick: DOWN ");} + else if (a > 0.2 && a < .3){tft.printf("Joystick: PUSHED ");} + else if (a > 0.3 && a < .65){tft.printf("Joystick: RIGHT ");} + else if (a > 0.65 && a < .725){tft.printf("Joystick: UP ");} + else if (a > 0.725){tft.printf("Joystick: DEFAULT");} + wait_ms(.5); + i++; + } + fclose(fp); + led1=0; + file_index++; + } } - -
--- a/mbed-os.lib Tue Jan 31 17:16:30 2017 +0000 +++ b/mbed-os.lib Mon Feb 27 17:49:04 2017 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/teams/onsemi/code/mbed-os/#098463de4c5d +http://developer.mbed.org/teams/onsemi/code/mbed-os/#f30bdcd2b33b