p
Dependencies: SDFileSystem SPI_TFT_ILI9341 TFT_fonts mbed
main.cpp@0:c9e8b902e5f1, 2015-12-08 (annotated)
- Committer:
- palmdotax
- Date:
- Tue Dec 08 14:35:24 2015 +0000
- Revision:
- 0:c9e8b902e5f1
palm
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
palmdotax | 0:c9e8b902e5f1 | 1 | #include "mbed.h" |
palmdotax | 0:c9e8b902e5f1 | 2 | #include "SPI_TFT_ILI9341.h" |
palmdotax | 0:c9e8b902e5f1 | 3 | #include "stdio.h" |
palmdotax | 0:c9e8b902e5f1 | 4 | #include "string" |
palmdotax | 0:c9e8b902e5f1 | 5 | #include "Arial12x12.h" |
palmdotax | 0:c9e8b902e5f1 | 6 | #include "Arial24x23.h" |
palmdotax | 0:c9e8b902e5f1 | 7 | #include "Arial28x28.h" |
palmdotax | 0:c9e8b902e5f1 | 8 | #include "font_big.h" |
palmdotax | 0:c9e8b902e5f1 | 9 | #include "SDFileSystem.h" |
palmdotax | 0:c9e8b902e5f1 | 10 | PwmOut mypwm(PWM_OUT); |
palmdotax | 0:c9e8b902e5f1 | 11 | SDFileSystem sd(SPI_MOSI, SPI_MISO, SPI_SCK, D7, "sd"); |
palmdotax | 0:c9e8b902e5f1 | 12 | DigitalOut myled(LED1); |
palmdotax | 0:c9e8b902e5f1 | 13 | PwmOut RED(D8); |
palmdotax | 0:c9e8b902e5f1 | 14 | PwmOut GREEN(D10); |
palmdotax | 0:c9e8b902e5f1 | 15 | PwmOut BLUE(D9); |
palmdotax | 0:c9e8b902e5f1 | 16 | InterruptIn button(USER_BUTTON); |
palmdotax | 0:c9e8b902e5f1 | 17 | extern unsigned char p1[]; |
palmdotax | 0:c9e8b902e5f1 | 18 | extern unsigned char p2[]; |
palmdotax | 0:c9e8b902e5f1 | 19 | extern unsigned char p3[]; |
palmdotax | 0:c9e8b902e5f1 | 20 | char List[4][8]={"track01","track02","track03","track04"}; |
palmdotax | 0:c9e8b902e5f1 | 21 | Serial pc(SERIAL_TX,SERIAL_RX); |
palmdotax | 0:c9e8b902e5f1 | 22 | // the TFT is connected to SPI pin 11-14 |
palmdotax | 0:c9e8b902e5f1 | 23 | int mark=10,list_nowplay=0; |
palmdotax | 0:c9e8b902e5f1 | 24 | SPI_TFT_ILI9341 TFT(SPI_MOSI,SPI_MISO,SPI_SCK,SPI_CS, D9, D8,"TFT"); // mosi, miso, sclk, cs, reset, dc |
palmdotax | 0:c9e8b902e5f1 | 25 | |
palmdotax | 0:c9e8b902e5f1 | 26 | void letplay() |
palmdotax | 0:c9e8b902e5f1 | 27 | { |
palmdotax | 0:c9e8b902e5f1 | 28 | TFT.cls(); |
palmdotax | 0:c9e8b902e5f1 | 29 | TFT.foreground(White); |
palmdotax | 0:c9e8b902e5f1 | 30 | TFT.background(Black); |
palmdotax | 0:c9e8b902e5f1 | 31 | TFT.cls(); |
palmdotax | 0:c9e8b902e5f1 | 32 | TFT.set_orientation(1); |
palmdotax | 0:c9e8b902e5f1 | 33 | TFT.Bitmap(60,1,200,173,p1); |
palmdotax | 0:c9e8b902e5f1 | 34 | } |
palmdotax | 0:c9e8b902e5f1 | 35 | void angry() |
palmdotax | 0:c9e8b902e5f1 | 36 | { |
palmdotax | 0:c9e8b902e5f1 | 37 | TFT.cls(); |
palmdotax | 0:c9e8b902e5f1 | 38 | TFT.foreground(White); |
palmdotax | 0:c9e8b902e5f1 | 39 | TFT.background(Black); |
palmdotax | 0:c9e8b902e5f1 | 40 | TFT.cls(); |
palmdotax | 0:c9e8b902e5f1 | 41 | TFT.set_orientation(1); |
palmdotax | 0:c9e8b902e5f1 | 42 | TFT.Bitmap(60,1,200,173,p2); |
palmdotax | 0:c9e8b902e5f1 | 43 | } |
palmdotax | 0:c9e8b902e5f1 | 44 | void cry() |
palmdotax | 0:c9e8b902e5f1 | 45 | { |
palmdotax | 0:c9e8b902e5f1 | 46 | TFT.cls(); |
palmdotax | 0:c9e8b902e5f1 | 47 | TFT.foreground(White); |
palmdotax | 0:c9e8b902e5f1 | 48 | TFT.background(Black); |
palmdotax | 0:c9e8b902e5f1 | 49 | TFT.cls(); |
palmdotax | 0:c9e8b902e5f1 | 50 | TFT.set_orientation(1); |
palmdotax | 0:c9e8b902e5f1 | 51 | TFT.Bitmap(60,1,200,173,p3); |
palmdotax | 0:c9e8b902e5f1 | 52 | } |
palmdotax | 0:c9e8b902e5f1 | 53 | void print_list() |
palmdotax | 0:c9e8b902e5f1 | 54 | { |
palmdotax | 0:c9e8b902e5f1 | 55 | int i=0,j=0; |
palmdotax | 0:c9e8b902e5f1 | 56 | TFT.claim(stdout); |
palmdotax | 0:c9e8b902e5f1 | 57 | TFT.cls(); |
palmdotax | 0:c9e8b902e5f1 | 58 | TFT.foreground(White); |
palmdotax | 0:c9e8b902e5f1 | 59 | TFT.background(Black); |
palmdotax | 0:c9e8b902e5f1 | 60 | TFT.cls(); |
palmdotax | 0:c9e8b902e5f1 | 61 | |
palmdotax | 0:c9e8b902e5f1 | 62 | TFT.set_orientation(3); |
palmdotax | 0:c9e8b902e5f1 | 63 | TFT.set_font((unsigned char*) Arial28x28); |
palmdotax | 0:c9e8b902e5f1 | 64 | TFT.locate(150,120); |
palmdotax | 0:c9e8b902e5f1 | 65 | TFT.printf("Manual Mode:"); |
palmdotax | 0:c9e8b902e5f1 | 66 | TFT.cls(); |
palmdotax | 0:c9e8b902e5f1 | 67 | TFT.set_orientation(3); |
palmdotax | 0:c9e8b902e5f1 | 68 | TFT.set_font((unsigned char*) Arial24x23); |
palmdotax | 0:c9e8b902e5f1 | 69 | do |
palmdotax | 0:c9e8b902e5f1 | 70 | { |
palmdotax | 0:c9e8b902e5f1 | 71 | TFT.locate(5,j); |
palmdotax | 0:c9e8b902e5f1 | 72 | TFT.printf("%2d . %s\r\n", i,List[i]); |
palmdotax | 0:c9e8b902e5f1 | 73 | i++; |
palmdotax | 0:c9e8b902e5f1 | 74 | j=j+23; |
palmdotax | 0:c9e8b902e5f1 | 75 | }while(i<4); |
palmdotax | 0:c9e8b902e5f1 | 76 | |
palmdotax | 0:c9e8b902e5f1 | 77 | } |
palmdotax | 0:c9e8b902e5f1 | 78 | void select_list() |
palmdotax | 0:c9e8b902e5f1 | 79 | { |
palmdotax | 0:c9e8b902e5f1 | 80 | //i=10; |
palmdotax | 0:c9e8b902e5f1 | 81 | if(mark>=96) |
palmdotax | 0:c9e8b902e5f1 | 82 | { |
palmdotax | 0:c9e8b902e5f1 | 83 | mark=10; |
palmdotax | 0:c9e8b902e5f1 | 84 | } |
palmdotax | 0:c9e8b902e5f1 | 85 | TFT.cls(); |
palmdotax | 0:c9e8b902e5f1 | 86 | print_list(); |
palmdotax | 0:c9e8b902e5f1 | 87 | TFT.set_orientation(0); |
palmdotax | 0:c9e8b902e5f1 | 88 | TFT.fillcircle(mark,20,10,Red); |
palmdotax | 0:c9e8b902e5f1 | 89 | |
palmdotax | 0:c9e8b902e5f1 | 90 | mark=mark+23; |
palmdotax | 0:c9e8b902e5f1 | 91 | list_nowplay++; |
palmdotax | 0:c9e8b902e5f1 | 92 | //pc.printf("%d\n",list_nowplay); |
palmdotax | 0:c9e8b902e5f1 | 93 | } |
palmdotax | 0:c9e8b902e5f1 | 94 | void SmoothRed() |
palmdotax | 0:c9e8b902e5f1 | 95 | { |
palmdotax | 0:c9e8b902e5f1 | 96 | int i,j; |
palmdotax | 0:c9e8b902e5f1 | 97 | for(i=0.0;i<=1.0;i+=0.1) |
palmdotax | 0:c9e8b902e5f1 | 98 | { |
palmdotax | 0:c9e8b902e5f1 | 99 | RED.write(i); |
palmdotax | 0:c9e8b902e5f1 | 100 | wait(1); |
palmdotax | 0:c9e8b902e5f1 | 101 | for(j=0.0;j<=1.0;j+=0.1) |
palmdotax | 0:c9e8b902e5f1 | 102 | { |
palmdotax | 0:c9e8b902e5f1 | 103 | GREEN.write(j); |
palmdotax | 0:c9e8b902e5f1 | 104 | wait(1); |
palmdotax | 0:c9e8b902e5f1 | 105 | } |
palmdotax | 0:c9e8b902e5f1 | 106 | } |
palmdotax | 0:c9e8b902e5f1 | 107 | |
palmdotax | 0:c9e8b902e5f1 | 108 | /* for(i=1.0;i>=0;i-=0.1) |
palmdotax | 0:c9e8b902e5f1 | 109 | { |
palmdotax | 0:c9e8b902e5f1 | 110 | RED.write(i); |
palmdotax | 0:c9e8b902e5f1 | 111 | wait(1); |
palmdotax | 0:c9e8b902e5f1 | 112 | }*/ |
palmdotax | 0:c9e8b902e5f1 | 113 | |
palmdotax | 0:c9e8b902e5f1 | 114 | } |
palmdotax | 0:c9e8b902e5f1 | 115 | |
palmdotax | 0:c9e8b902e5f1 | 116 | int main() |
palmdotax | 0:c9e8b902e5f1 | 117 | { |
palmdotax | 0:c9e8b902e5f1 | 118 | // print_list(); |
palmdotax | 0:c9e8b902e5f1 | 119 | // select_list(); |
palmdotax | 0:c9e8b902e5f1 | 120 | // button.rise(&select_list); |
palmdotax | 0:c9e8b902e5f1 | 121 | while(1) |
palmdotax | 0:c9e8b902e5f1 | 122 | { |
palmdotax | 0:c9e8b902e5f1 | 123 | SmoothRed(); |
palmdotax | 0:c9e8b902e5f1 | 124 | wait(2); |
palmdotax | 0:c9e8b902e5f1 | 125 | } |
palmdotax | 0:c9e8b902e5f1 | 126 | |
palmdotax | 0:c9e8b902e5f1 | 127 | } |