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:
- MetropoliaMies
- Date:
- 2014-01-30
- Revision:
- 3:c8a476a218e3
- Parent:
- 2:478274cba6c3
- Child:
- 4:76c054f8b97e
File content as of revision 3:c8a476a218e3:
#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 PwmOut led1(LED1); PwmOut led2(LED2); PwmOut led3(LED3); PwmOut led4(LED4); int q,w,e,r,s; float brightness = 0.0; 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); brightness += 0.01; } } if (p.y > 163 && p.y < 238) { //ROW B if (p.x > 3 && p.x < 78) { //button 4 buttons(4, color); s = 1; } if (p.x > 83 && p.x < 158) { //button 5 buttons(5, color); led1 = 0.5; } if (p.x > 163 && p.x < 238) { //button 6 buttons(6, color); s = 2; } } 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); brightness -= 0.01; } } } 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(90,0); // -------Kirkkaushömppää-------- printf(" B = "); if (q = brightness && s = 1) { q = 0; w = brightness; } if (w = brightness && s = 1) { w = 0; e = brightness; } tft.locate(0,0); printf(" MIDIMAN! "); tft.line(0,83,239,83,White); while (1) { color = White; draw_buttons(color); led1 = q; led2 = w; led3 = e; led4 = r; 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(210,0); printf("%3d",p.x); tft.locate(210,12); printf("%3d",p.y); tft.locate(100,0); printf("%f", brightness); } } }