ccc

<<code>> example to test the TFT Display Thanks to the GraphicsDisplay and TextDisplay classes test2.bmp has to be on the mbed file system

  1. include <iostream>
  2. include "stdio.h"
  3. include "mbed.h"
  4. include "SPI_TFT_ILI9341.h"
  5. include "string"
  6. include "Arial12x12.h"
  7. include "Arial24x23.h"
  8. include "Arial28x28.h"
  9. include "font_big.h"
  10. include "touch_tft.h"
  11. include "TSL2561.h"
  12. include "mbed.h"
  1. define PC_PRINTX(z,x) if(z==1) tft.printf(x);
  2. define PC_PRINTLNX(z,x) if(z==1) {tft.printf(x); tft.printf("\r\n");}
  3. define PC_PRINTXY(z,x, y) if(z==1) tft.printf(x, y);
  4. define PC_PRINTLNXY(z,x, y) if(z==1) {tft.printf(x, y); tft.printf("\r\n");}

char menu;

char t, t2, t3;

touch_tft tft(p20,p18,p19,p17,p5, p6, p7, p16, p15, p21,"TFT"); x+,x-,y+,y-,mosi, miso, sclk, cs, reset, dc

DigitalOut LCD_LED(p21); the Watterott display has a backlight switch DigitalOut CS_Touch(p16); disable the touch controller on the Watterott display

the TFT is connected to SPI pin 5-7 SPI_TFT_ILI9341 TFT(p5, p6, p7, p16, p15, p21,"TFT"); mosi, miso, sclk, cs, reset, dc

void touch(void);

--LUX SENSOR start -- I2C i2c(p28, p27); Timer setuptimer; Timer executetimer;

TSL2561 tsl2561(TSL2561_ADDR_FLOAT);

void setup(void) {

if (tsl2561.begin()) { TFT.set_orientation(1); TFT.locate(0,0); printf("TSL2561 Sensor Found"); } else { printf("TSL2561 Sensor not Found"); }

You can change the gain on the fly, to adapt to brighter/dimmer tsl2561 situations

tsl2561.setGain(TSL2561_GAIN_0X); set no gain (for bright situtations)

tsl2561.setGain(TSL2561_GAIN_16X); set 16x gain (for dim situations)

Changing the integration time gives you a longer time over which to sense tsl2561 longer timelines are slower, but are good in very low tsl2561 situtations! tsl2561.setTiming(TSL2561_INTEGRATIONTIME_13MS); shortest integration time (bright tsl2561) tsl2561.setTiming(TSL2561_INTEGRATIONTIME_101MS); medium integration time (medium tsl2561) tsl2561.setTiming(TSL2561_INTEGRATIONTIME_402MS); longest integration time (dim tsl2561)

Now we're ready to get readings! } --LUX SENSOR end --

--jannen pointp start-- point p;

void touch() { while(1) { p.x=0; p.y=0; p = tft.get_touch(); read analog pos. if (tft.is_touched(p)) { test if touched p = tft.to_pixel(p); convert to pixel pos Debug pc.printf("\n\r Point x:%d", p.x); pc.printf("\n\r Point y:%d", p.y); wait_ms(100); give some time to remove finger break; } } }

--jannen pointp end--

int main() {

LCD_LED = 1; backlight on CS_Touch = 1;

BITMAP PRINT int BMP_16 (unsigned int 0, unsigned int 0, const char* test);

tft.claim(stdout); send stdout to the TFT display tft.background(Black); set background to black tft.foreground(White); set chars to white tft.cls(); clear the screen tft.set_font((unsigned char*) Arial12x12); select the font tft.set_orientation(1);

tft.calibrate(); calibrate the touch

-Menu place definitions-start- while(1) {

black background

tft.fillrect(0,200,320,240,Black);

Drawing of buttons outer lines tft.rect(0,200,320,240,Red);

Keyboard only row, inlines tft.line(74,200,74,240,Red); tft.line(162,200,162,240,Red); tft.line(267,200,267,240,Red);

tft.locate(16,220); tft.printf("paint"); tft.locate(94,220); tft.printf("sensor"); tft.locate(182,220); tft.printf("main"); break;

}; -Menu place definitions-end-

--Menu valinnat-start-

while(1) { touch();

Debug pc.printf("\n\r Keyboard Case 2. P.x:%d and P.y:%d",p.x,p.y); tft.background(LightGrey);

main:

if((p.x>0 && p.x<=73) && (p.y>=200 && p.y<=240)) { paint selector button

while (1) { p = tft.get_touch(); read analog pos.

if (tft.is_touched(p)) { test if touched p = tft.to_pixel(p); convert to pixel pos tft.fillcircle(p.x,p.y,3,Blue); print a blue dot on the screen

} if ((p.x>=163 && p.x<=266) && (p.y>=200 && p.y<=240)) { go back to main selection.. ((p.x>=163 && p.x<=266) && (p.y>=200 && p.y<=240)){ goto main; } } }

else if((p.x>=75 && p.x<=161) && (p.y>=200 && p.y<=240)) { sensor selector button

tft.printf("\n-START-\n\n");

setuptimer.start(); setup(); setuptimer.stop(); PC_PRINTLNXY (1, "Setup time: %f",setuptimer.read()); setuptimer.reset();

uint16_t x,y,z;

while(1) {

Simple data read example. Just read the infrared, fullspecrtrum diode or 'visible' (difference between the two) channels. This can take 13-402 milliseconds! Uncomment whichever of the following you want to read executetimer.start(); x = tsl2561.getLuminosity(TSL2561_VISIBLE); y = tsl2561.getLuminosity(TSL2561_FULLSPECTRUM); z = tsl2561.getLuminosity(TSL2561_INFRARED); executetimer.stop();

tft.locate(50,100);

tft.cls();

PC_PRINTLNXY(1,"Visible: %d",x); PC_PRINTLNXY(1,"Full Spectrum: %d",y); PC_PRINTLNXY(1,"Infrared: %d",z); PC_PRINTLNXY(1,"Execution Time: %f",executetimer.read()); executetimer.reset();

p = tft.get_touch(); read analog pos.

if (tft.is_touched(p)) { test if touched p = tft.to_pixel(p); convert to pixel pos wait_ms(100); give some time to remove finger

if ((p.x>=163 && p.x<=266) && (p.y>=200 && p.y<=240)) { go back to main selection.. ((p.x>=163 && p.x<=266) && (p.y>=200 && p.y<=240)){ goto main; } } wait(2);

}

}

} if((p.x>=162 && p.x<=266) && (p.y>=200 && p.y<=240)) goto main; main if((p.x>=267 && p.x<=320) && (p.y>=200 && p.y<=240)){key='\n';}; enter

break;

/* paint: while (1) { p = tft.get_touch(); read analog pos. if (tft.is_touched(p)) { test if touched p = tft.to_pixel(p); convert to pixel pos tft.fillcircle(p.x,p.y,3,Red); print a blue dot on the screen }

KOKEILE switch case paint...

sensor:

tft.printf("\n-START-");

setuptimer.start(); setup(); setuptimer.stop(); PC_PRINTLNXY (1, "Setup time: %f",setuptimer.read()); setuptimer.reset();

uint16_t x,y,z;

while(1) {

Simple data read example. Just read the infrared, fullspecrtrum diode or 'visible' (difference between the two) channels. This can take 13-402 milliseconds! Uncomment whichever of the following you want to read executetimer.start(); x = tsl2561.getLuminosity(TSL2561_VISIBLE); y = tsl2561.getLuminosity(TSL2561_FULLSPECTRUM); z = tsl2561.getLuminosity(TSL2561_INFRARED); executetimer.stop();

TFT.locate(50,100);

tft.cls();

PC_PRINTLNXY(1,"Visible: %d",x); PC_PRINTLNXY(1,"Full Spectrum: %d",y); PC_PRINTLNXY(1,"Infrared: %d",z); PC_PRINTLNXY(1,"Execution Time: %f",executetimer.read()); executetimer.reset(); wait(2); }

  • / <--LUX-end--------- --LUX 32bit READ--

/* More advanced data read example. Read 32 bits with top 16 bits IR, bottom 16 bits full spectrum That way you can do whatever math and comparisons you want! uint32_t lum = tsl2561.getFullLuminosity(); uint16_t ir, full; ir = lum >> 16; full = lum & 0xFFFF; PC_PRINTLNXY(1,"Visible: %d",full - ir); PC_PRINTLNXY(1,"Full Spectrum: %d",full); PC_PRINTLNXY(1,"Infrared: %d",ir);

wait(1);

TFT.printf("\n-COMPLETE-"); wait(2);

  • /

<---LUX 32bit READ-end---

-main while loop-end-

-paint liitännäinen /* point p;

tft.claim(stdout); send stdout to the TFT display tft.background(Black); set background to black tft.foreground(White); set chars to white tft.cls(); clear the screen tft.set_font((unsigned char*) Arial12x12); select the font tft.set_orientation(1);

tft.calibrate(); calibrate the touch

  • /

/* --Paint toimii ilman goto komentoa-start- while (1) { p = tft.get_touch(); read analog pos. if (tft.is_touched(p)) { test if touched p = tft.to_pixel(p); convert to pixel pos tft.fillcircle(p.x,p.y,3,Red); print a blue dot on the screen } */ --Paint toimii ilman goto komentoa-end-

----PRINT BITMAP----- /* TFT.background(Black); TFT.cls();

TFT.locate(10,10); TFT.printf("Graphic from Flash");

TFT.Bitmap(90,90,172,55,p1);

wait(5);

TFT.cls(); TFT.locate(10,10); TFT.printf("Graphic from File System"); TFT.locate(10,20); TFT.printf("open test.bmp"); int err = TFT.BMP_16(20,50,"test.bmp"); if (err != 1) TFT.printf(" - Err: %d",err);

wait(5);

point p;

tt.claim(stdout); send stdout to the TFT display tt.background(Black); set background to black tt.foreground(White); set chars to white tt.cls(); clear the screen tt.set_font((unsigned char*) Arial12x12); select the font tt.set_orientation(1);

tt.calibrate(); calibrate the touch while (1) { p = tt.get_touch(); read analog pos. if (tt.is_touched(p)) { test if touched p = tt.to_pixel(p); convert to pixel pos tt.fillcircle(p.x,p.y,3,Red); print a blue dot on the screen } }

  • / <--LUX--------- TFT.set_font((unsigned char*) Arial12x12);

} <<code>>


1 comment on ccc:

24 Feb 2014

<<code>> example to test the TFT Display Thanks to the GraphicsDisplay and TextDisplay classes test2.bmp has to be on the mbed file system

  1. include <iostream>d to black tt.foreground(White); set chars to white tt.cls(); clear the screen tt.set_font((unsigned char*) Arial12x12); select the font tt.set_orientation(1);

tt.calibrate(); calibrate the touch while (1) { p = tt.get_touch(); read analog pos. if (tt.is_touched(p)) { test if touched p = tt.to_pixel(p); convert to pixel pos tt.fillcircle(p.x,p.y,3,Red); print a blue dot on the screen } }

  • / <--LUX--------- TFT.set_font((unsigned char*) Arial12x12);

} <<code>>

Please log in to post comments.