acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
TFT_Float_Test.ino (2318B)
1 /* 2 Tests the updated floating point plot function 3 The datum is set to the centre of the 320 x 240 screen 4 so numbers are printed the middle. 5 6 The last test shows the datum point as a red dot. 7 8 Normally strings are printed relative to the top left corner but this can be 9 changed with the setTextDatum() function. The library has #defines for: 10 11 TL_DATUM 0 //Top left 12 TC_DATUM 1 //Top centre 13 TR_DATUM 2 //Top right 14 ML_DATUM 3 //Middle left 15 MC_DATUM 4 //Middle centre 16 MR_DATUM 5 //Middle right 17 BL_DATUM 6 //Bottom left 18 BC_DATUM 7 //Bottom centre 19 BR_DATUM 8 //Bottom right 20 21 22 Needs fonts 2 and 6 23 24 Make sure all the display driver and pin connections are correct by 25 editing the User_Setup.h file in the TFT_eSPI library folder. 26 27 ######################################################################### 28 ###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ###### 29 ######################################################################### 30 */ 31 32 33 #include <TFT_eSPI.h> // Hardware-specific library 34 #include <SPI.h> 35 36 TFT_eSPI tft = TFT_eSPI(); // Invoke custom library 37 38 unsigned long drawTime = 0; 39 40 void setup(void) { 41 Serial.begin(115200); 42 tft.init(); 43 tft.setRotation(1); 44 45 } 46 47 void loop() { 48 49 char tmp[12]; 50 51 tft.fillScreen(TFT_BLACK); 52 tft.setTextColor(TFT_WHITE, TFT_BLACK); 53 54 // Datum is middle centre 55 tft.setTextDatum(MC_DATUM); 56 57 // Test floating point drawing function: 58 // drawFloat(value, precision, x, y, font); 59 60 float test = 67.125; 61 tft.drawFloat(test, 4, 160, 120, 6); 62 tft.drawString(dtostrf(test,4,4,tmp), 100, 200, 6); 63 64 delay(1000); 65 tft.fillScreen(TFT_BLACK); 66 67 test = -0.555555; 68 tft.drawFloat(test, 3, 160, 120, 6); 69 tft.drawString(dtostrf(test,2,2,tmp), 100, 200, 6); 70 71 delay(1000); 72 tft.fillScreen(TFT_BLACK); 73 74 test = 0.123; 75 tft.drawFloat(test, 4, 160, 120, 6); 76 77 tft.drawString(dtostrf(test,4,4,tmp), 100, 200, 6); 78 79 delay(1000); 80 tft.fillScreen(TFT_BLACK); 81 82 // This does not work at the moment.... 83 test = 9999999; 84 tft.drawFloat(test, 0, 160, 120, 6); 85 tft.drawString(dtostrf(test,4,4,tmp), 100, 200, 6); 86 delay(1000); 87 88 //Plot the datum for the last number 89 tft.fillCircle(160,120,5,TFT_RED); 90 tft.setTextDatum(MC_DATUM); 91 tft.setTextColor(TFT_BLACK); 92 tft.drawString("X", 160, 120, 2); 93 94 delay(4000); 95 } 96 97 98 99 100 101 102 103