Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SPI_TFT_ILI9341 TFT_fonts Touch_tft PowerControl mbed USBMIDI
main.cpp
- Committer:
- Vekotin
- Date:
- 2014-01-20
- Revision:
- 2:478274cba6c3
- Parent:
- 1:7e2d93d70d2b
- Child:
- 3:c8a476a218e3
- Child:
- 14:31d5531114e0
File content as of revision 2:478274cba6c3:
#include "mbed.h" #include "SPI_TFT_ILI9341.h" #include "Arial12x12.h" #include "Arial28x28.h" #include "touch_tft.h" #include "USBMIDI.h" // the TFT is connected to SPI pin 5-7 // the touch is connected to 19,20,16,17 touch_tft tft(p20,p19,p18,p17,p5, p6, p7, p14, p15, p21, "TFT"); // x+,x-,y+,y-,mosi, miso, sclk, cs, reset, dc void buttons(int b, unsigned short color) { //button field if (b == 1) { tft.fillrect(3,88,78,158,color); } if (b == 2) { tft.fillrect(83,88,158,158,color); } if (b == 3) { tft.fillrect(163,88,238,158,color); } if (b == 4) { tft.fillrect(3,163,78,238,color); } if (b == 5) { tft.fillrect(83,163,158,238,color); } if (b == 6) { tft.fillrect(163,163,238,238,color); } if (b == 7) { tft.fillrect(3,243,78,318,color); } if (b == 8) { tft.fillrect(83,243,158,318,color); } if (b == 9) { tft.fillrect(163,243,238,318,color); } } void draw_buttons(unsigned short color) { unsigned int i = 1; for (i = 1; i<10; i++){ //draw buttons buttons(i, color); } } void light_pressed(unsigned short color, point p) { if (p.y > 88 && p.y < 158) { //ROW A if (p.x > 3 && p.x < 78) { //button 1 buttons(1, color); } if (p.x > 83 && p.x < 158) { //button 2 buttons(2, color); } if (p.x > 163 && p.x < 238) { //button 3 buttons(3, color); } } if (p.y > 163 && p.y < 238) { //ROW B if (p.x > 3 && p.x < 78) { //button 4 buttons(4, color); } if (p.x > 83 && p.x < 158) { //button 5 buttons(5, color); } if (p.x > 163 && p.x < 238) { //button 6 buttons(6, color); } } if (p.y > 243 && p.y < 318) { //ROW C if (p.x > 3 && p.x < 78) { //button 7 buttons(7, color); } if (p.x > 83 && p.x < 158) { //button 8 buttons(8, color); } if (p.x > 163 && p.x < 238) { //button 9 buttons(9, color); } } } int main() { // PERUSPOHJA, ÄLÄ MUOKKAA! point p; unsigned short color = White; 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(0); tft.calibrate(); tft.locate(180,0); //show coordinates printf(" x = "); tft.locate(180,12); printf(" y = "); tft.locate(0,0); printf(" MIDIMAN! "); tft.line(0,83,239,83,White); while (1) { color = White; draw_buttons(color); while (tft.is_touched(tft.get_touch())) { // touch p = tft.get_touch(); p = tft.to_pixel(p); // convert to pixel position light_pressed(Red,p); // light pressed button tft.locate(216,0); printf("%3d",p.x); tft.locate(216,12); printf("%3d",p.y); } } }