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 Jacob Johnson

Committer:
jacobjohnson
Date:
Mon Feb 27 17:49:04 2017 +0000
Revision:
3:81a34c232d99
Parent:
2:fa3fb1787cf8
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

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jacobjohnson 2:fa3fb1787cf8 1 /***************************************
jacobjohnson 3:81a34c232d99 2 Example Application for the Adafruit ST7735 TFT Shield
jacobjohnson 3:81a34c232d99 3 on the ON Semiconductor NCS36510 mbed Board
jacobjohnson 2:fa3fb1787cf8 4 ***************************************/
jacobjohnson 2:fa3fb1787cf8 5
jacobjohnson 0:8fbbced097c5 6 #include "mbed.h"
jacobjohnson 2:fa3fb1787cf8 7 #include "Adafruit_ST7735.h"
jacobjohnson 2:fa3fb1787cf8 8 #include "SDFileSystem.h"
jacobjohnson 3:81a34c232d99 9 #include <string>
jacobjohnson 3:81a34c232d99 10 #include <sstream>
jacobjohnson 3:81a34c232d99 11
jacobjohnson 3:81a34c232d99 12 using namespace std;
jacobjohnson 3:81a34c232d99 13
jacobjohnson 0:8fbbced097c5 14
jacobjohnson 0:8fbbced097c5 15 DigitalOut led1(LED1);
jacobjohnson 3:81a34c232d99 16 AnalogIn adc_in_3(A3);
jacobjohnson 3:81a34c232d99 17 AnalogIn adc_in_2(A2);
jacobjohnson 3:81a34c232d99 18
jacobjohnson 2:fa3fb1787cf8 19 SDFileSystem sd(D11, D12, D13, D4, "SD"); // the pinout on the mbed // mosi, miso, sclk, cs
jacobjohnson 2:fa3fb1787cf8 20 Adafruit_ST7735 tft(D11, D12, D13, D10, D6, D9); // MOSI, MISO, SCLK, SSEL, TFT_DC, TFT_RST
jacobjohnson 0:8fbbced097c5 21
jacobjohnson 3:81a34c232d99 22 Serial PC(USBTX, USBRX);
jacobjohnson 3:81a34c232d99 23
jacobjohnson 2:fa3fb1787cf8 24
jacobjohnson 0:8fbbced097c5 25 int main() {
jacobjohnson 3:81a34c232d99 26 PC.printf("start");
jacobjohnson 3:81a34c232d99 27
jacobjohnson 2:fa3fb1787cf8 28 tft.initR(INITR_BLACKTAB); // initialize a ST7735S chip, black tab
jacobjohnson 2:fa3fb1787cf8 29 tft.fillScreen(ST7735_BLACK);
jacobjohnson 3:81a34c232d99 30 tft.DrawBitmapFile("/SD/ON.bmp"); //Note, this must be a 24-bit Bitmap file, with a resolution less than 128x160 pixels
jacobjohnson 0:8fbbced097c5 31
jacobjohnson 3:81a34c232d99 32 float a, b;
jacobjohnson 3:81a34c232d99 33 uint32_t file_index = 0;
jacobjohnson 3:81a34c232d99 34
jacobjohnson 2:fa3fb1787cf8 35 while (true) {
jacobjohnson 2:fa3fb1787cf8 36
jacobjohnson 3:81a34c232d99 37 stringstream temp_str;
jacobjohnson 3:81a34c232d99 38 temp_str<<(file_index);
jacobjohnson 3:81a34c232d99 39 string filename_str = "/SD/data" + temp_str.str() + ".csv";
jacobjohnson 3:81a34c232d99 40 const char* filename_cstr = filename_str.c_str();
jacobjohnson 3:81a34c232d99 41 FILE *fp = fopen(filename_cstr, "w");
jacobjohnson 3:81a34c232d99 42 led1=1;
jacobjohnson 3:81a34c232d99 43
jacobjohnson 2:fa3fb1787cf8 44
jacobjohnson 3:81a34c232d99 45 uint32_t i = 0;
jacobjohnson 3:81a34c232d99 46 while (i < 50){
jacobjohnson 3:81a34c232d99 47 a = adc_in_3.read(); /* Read the converted analog value */
jacobjohnson 3:81a34c232d99 48 b = adc_in_2.read();
jacobjohnson 3:81a34c232d99 49 fprintf(fp,"%f\n", a);
jacobjohnson 3:81a34c232d99 50 tft.setTextColor(ST7735_GREEN, ST7735_BLACK); //(Text Color, Background color)
jacobjohnson 3:81a34c232d99 51 tft.setTextCursor(0, 120);
jacobjohnson 3:81a34c232d99 52 tft.printf("ADC 3: %f\n\rADC 2: %f\n\r", (a), (b));
jacobjohnson 3:81a34c232d99 53 if (a < 0.1){tft.printf("Joystick: LEFT ");}
jacobjohnson 3:81a34c232d99 54 else if (a > 0.1 && a < .2){tft.printf("Joystick: DOWN ");}
jacobjohnson 3:81a34c232d99 55 else if (a > 0.2 && a < .3){tft.printf("Joystick: PUSHED ");}
jacobjohnson 3:81a34c232d99 56 else if (a > 0.3 && a < .65){tft.printf("Joystick: RIGHT ");}
jacobjohnson 3:81a34c232d99 57 else if (a > 0.65 && a < .725){tft.printf("Joystick: UP ");}
jacobjohnson 3:81a34c232d99 58 else if (a > 0.725){tft.printf("Joystick: DEFAULT");}
jacobjohnson 3:81a34c232d99 59 wait_ms(.5);
jacobjohnson 3:81a34c232d99 60 i++;
jacobjohnson 3:81a34c232d99 61 }
jacobjohnson 3:81a34c232d99 62 fclose(fp);
jacobjohnson 3:81a34c232d99 63 led1=0;
jacobjohnson 3:81a34c232d99 64 file_index++;
jacobjohnson 3:81a34c232d99 65
jacobjohnson 2:fa3fb1787cf8 66
jacobjohnson 0:8fbbced097c5 67 }
jacobjohnson 0:8fbbced097c5 68 }
jacobjohnson 0:8fbbced097c5 69