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: poirier-proj-95 TFT_fonts mbed
main.cpp@3:24069293d35d, 2015-09-15 (annotated)
- Committer:
- dujardin
- Date:
- Tue Sep 15 16:09:10 2015 +0000
- Revision:
- 3:24069293d35d
- Parent:
- 2:1d66e2e776bc
- Child:
- 4:56b453735e89
base pour des projets de S3; IUT de cergy Neuville ; cr?ation : dujardin
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| lawliet | 1:b2794eb7c940 | 1 | /* |
| lawliet | 1:b2794eb7c940 | 2 | main.cpp |
| lawliet | 1:b2794eb7c940 | 3 | 2014 Copyright (c) Seeed Technology Inc. All right reserved. |
| dujardin | 2:1d66e2e776bc | 4 | recompilé à partir d'une librairy donnée par |
| dujardin | 2:1d66e2e776bc | 5 | :lawliet zou(lawliet.zou@gmail.com) |
| dujardin | 2:1d66e2e776bc | 6 | This library is free software; you can redistribute it and/or |
| dujardin | 2:1d66e2e776bc | 7 | modify it under the terms of the GNU Lesser General Public |
| lawliet | 1:b2794eb7c940 | 8 | */ |
| lawliet | 1:b2794eb7c940 | 9 | |
| neilt6 | 0:407dafce805d | 10 | #include "mbed.h" |
| neilt6 | 0:407dafce805d | 11 | #include "SeeedStudioTFTv2.h" |
| neilt6 | 0:407dafce805d | 12 | #include "Arial12x12.h" |
| neilt6 | 0:407dafce805d | 13 | #include "Arial24x23.h" |
| neilt6 | 0:407dafce805d | 14 | #include "Arial28x28.h" |
| neilt6 | 0:407dafce805d | 15 | #include "font_big.h" |
| dujardin | 2:1d66e2e776bc | 16 | #include "diver.h" |
| dujardin | 3:24069293d35d | 17 | PwmOut rled(LED_RED); // init |
| dujardin | 3:24069293d35d | 18 | PwmOut gled(LED_GREEN); |
| dujardin | 3:24069293d35d | 19 | PwmOut bled(LED_BLUE); |
| dujardin | 2:1d66e2e776bc | 20 | SeeedStudioTFTv2 TFT(PTB3, PTB1, PTB2, PTB0, PTD2, PTD3, PTD1, PTA5, PTC8, PTC9, PTA4); |
| lawliet | 1:b2794eb7c940 | 21 | |
| neilt6 | 0:407dafce805d | 22 | |
| neilt6 | 0:407dafce805d | 23 | int main() |
| neilt6 | 0:407dafce805d | 24 | { |
| dujardin | 3:24069293d35d | 25 | // init I2C accélero |
| dujardin | 3:24069293d35d | 26 | uint8_t data[2] = {REG_CTRL_REG_1, 0x01}; |
| dujardin | 3:24069293d35d | 27 | i2c.write(MMA8451_I2C_ADDRESS,(char *)data,2); |
| dujardin | 3:24069293d35d | 28 | |
| dujardin | 3:24069293d35d | 29 | // initially set leds off |
| dujardin | 3:24069293d35d | 30 | rled=1.0f; |
| dujardin | 3:24069293d35d | 31 | gled=1.0f; |
| dujardin | 3:24069293d35d | 32 | bled=1.0f; |
| dujardin | 3:24069293d35d | 33 | // 1ms pwm frequency |
| dujardin | 3:24069293d35d | 34 | rled.period(0.001f); |
| dujardin | 3:24069293d35d | 35 | gled.period(0.001f); |
| dujardin | 3:24069293d35d | 36 | bled.period(0.001f); |
| dujardin | 3:24069293d35d | 37 | |
| dujardin | 3:24069293d35d | 38 | |
| dujardin | 2:1d66e2e776bc | 39 | //Configure l'afficheur TFT |
| neilt6 | 0:407dafce805d | 40 | TFT.background(Black); |
| neilt6 | 0:407dafce805d | 41 | TFT.foreground(White); |
| dujardin | 2:1d66e2e776bc | 42 | TFT.cls(); |
| neilt6 | 0:407dafce805d | 43 | |
| dujardin | 2:1d66e2e776bc | 44 | //Print : message de bonjour |
| dujardin | 2:1d66e2e776bc | 45 | TFT.set_font((unsigned char*) Arial28x28); |
| neilt6 | 0:407dafce805d | 46 | TFT.locate(0,0); |
| dujardin | 3:24069293d35d | 47 | TFT.printf("Bonjour "); |
| neilt6 | 0:407dafce805d | 48 | |
| dujardin | 3:24069293d35d | 49 | //Wait for 1 seconds |
| dujardin | 3:24069293d35d | 50 | wait(1.0); |
| neilt6 | 0:407dafce805d | 51 | |
| dujardin | 3:24069293d35d | 52 | //Draw some graphics // inutile sauf comme exemple de programmation |
| neilt6 | 0:407dafce805d | 53 | TFT.cls(); |
| neilt6 | 0:407dafce805d | 54 | TFT.set_font((unsigned char*) Arial24x23); |
| neilt6 | 0:407dafce805d | 55 | TFT.locate(100,100); |
| neilt6 | 0:407dafce805d | 56 | TFT.printf("Graphic"); |
| neilt6 | 0:407dafce805d | 57 | |
| neilt6 | 0:407dafce805d | 58 | TFT.line(0,0,100,0,Green); |
| neilt6 | 0:407dafce805d | 59 | TFT.line(0,0,0,200,Green); |
| neilt6 | 0:407dafce805d | 60 | TFT.line(0,0,100,200,Green); |
| neilt6 | 0:407dafce805d | 61 | |
| neilt6 | 0:407dafce805d | 62 | TFT.rect(100,50,150,100,Red); |
| neilt6 | 0:407dafce805d | 63 | TFT.fillrect(180,25,220,70,Blue); |
| neilt6 | 0:407dafce805d | 64 | |
| neilt6 | 0:407dafce805d | 65 | TFT.circle(80,150,33,White); |
| neilt6 | 0:407dafce805d | 66 | TFT.fillcircle(160,190,20,Yellow); |
| neilt6 | 0:407dafce805d | 67 | |
| neilt6 | 0:407dafce805d | 68 | double s; |
| neilt6 | 0:407dafce805d | 69 | for (int i = 0; i < 320; i++) { |
| neilt6 | 0:407dafce805d | 70 | s = 20 * sin((long double)i / 10); |
| neilt6 | 0:407dafce805d | 71 | TFT.pixel(i, 100 + (int)s, Red); |
| neilt6 | 0:407dafce805d | 72 | } |
| neilt6 | 0:407dafce805d | 73 | |
| dujardin | 3:24069293d35d | 74 | //Wait for 1 seconds |
| dujardin | 3:24069293d35d | 75 | wait(1.0); |
| neilt6 | 0:407dafce805d | 76 | |
| dujardin | 3:24069293d35d | 77 | //Multiple fonts // vous montre d'autres choses |
| neilt6 | 0:407dafce805d | 78 | TFT.foreground(White); |
| neilt6 | 0:407dafce805d | 79 | TFT.background(Blue); |
| neilt6 | 0:407dafce805d | 80 | TFT.cls(); |
| neilt6 | 0:407dafce805d | 81 | TFT.set_font((unsigned char*) Arial24x23); |
| neilt6 | 0:407dafce805d | 82 | TFT.locate(0,0); |
| neilt6 | 0:407dafce805d | 83 | TFT.printf("Different Fonts :"); |
| dujardin | 3:24069293d35d | 84 | |
| neilt6 | 0:407dafce805d | 85 | TFT.set_font((unsigned char*) Arial24x23); |
| neilt6 | 0:407dafce805d | 86 | TFT.locate(20,80); |
| neilt6 | 0:407dafce805d | 87 | TFT.printf("Hello Mbed 2"); |
| neilt6 | 0:407dafce805d | 88 | TFT.set_font((unsigned char*) Arial12x12); |
| neilt6 | 0:407dafce805d | 89 | TFT.locate(35,120); |
| neilt6 | 0:407dafce805d | 90 | TFT.printf("Hello Mbed 3"); |
| dujardin | 3:24069293d35d | 91 | |
| dujardin | 3:24069293d35d | 92 | while (true) { |
| dujardin | 3:24069293d35d | 93 | |
| dujardin | 3:24069293d35d | 94 | float xaccln,yaccln; |
| dujardin | 3:24069293d35d | 95 | xaccln=acclnread(REG_OUT_X_MSB); |
| dujardin | 3:24069293d35d | 96 | yaccln=acclnread(REG_OUT_Y_MSB); |
| dujardin | 3:24069293d35d | 97 | |
| dujardin | 3:24069293d35d | 98 | TFT.locate(35,220); |
| dujardin | 3:24069293d35d | 99 | TFT.printf("X: %1.4f, Y: %1.4f", xaccln, yaccln ); |
| dujardin | 3:24069293d35d | 100 | |
| dujardin | 3:24069293d35d | 101 | wait(0.1f); |
| dujardin | 3:24069293d35d | 102 | |
| dujardin | 3:24069293d35d | 103 | |
| dujardin | 3:24069293d35d | 104 | } |
| dujardin | 3:24069293d35d | 105 | |
| neilt6 | 0:407dafce805d | 106 | } |