kalibre

velocimetroBtA_1final

Mar 17th, 2024
980
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 1.84 KB | Software | 0 0
  1. //bem10jfx.blogspot.com
  2.  
  3. #include <Adafruit_GFX.h>
  4. #include <Adafruit_ST7735.h>
  5.  
  6. #define TFT_CS     10  //cs
  7. #define TFT_RST     12 //rebot
  8. #define TFT_DC     9  //sda
  9.  
  10. Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS,  TFT_DC, TFT_RST); //defs
  11.  int velocidadefinal;
  12.  
  13. void setup() {
  14.   Serial.begin(9600);
  15.  
  16. Serial.begin(9600);
  17.   tft.setCursor(0,30); //HEIGH, WIDTH //y,x
  18.   tft.initR(INITR_BLACKTAB); // TELAPRETA inicial?????????
  19.   tft.setTextSize(1); // FONTALIGMENT 1
  20.   tft.fillScreen(ST7735_BLACK); // color display
  21.   tft.setTextColor(ST7735_BLUE); //cor de  texto  
  22.   tft.print("Bem10jfx.blogspot.com"); //
  23.  
  24.   tft.setRotation(1.5);
  25.   desenharVelocimetro(0);  // Inicia o velocΓ­metro com velocidade zero
  26.  
  27. }
  28.  
  29. void loop() {
  30.   desenharVelocimetro(velocidadefinal);
  31.   Serial.println(velocidadefinal);
  32.    int velocidade = Serial.parseInt();  // LΓͺ a velocidadeserial
  33.    
  34.   if (Serial.available() > 0) {
  35.     velocidadefinal=velocidade;//guarda o ultimo valor ate chegar o proximo
  36.     desenharVelocimetro(velocidadefinal);
  37.   }
  38.  
  39.   delay(100);
  40. }
  41.  
  42. void desenharVelocimetro(int velocidade) {
  43.   int centroX = tft.width() / 2;//bind do limite
  44.   int centroY = tft.height() / 2;//de cordenadas do circle
  45.   int raio = min(tft.width(), tft.height()) / 3; //na tela dividido por2
  46.  
  47.   tft.fillCircle(centroX, centroY, raio, ST7735_BLACK);
  48.   tft.fillCircle(centroX, centroY, raio - 10, ST7735_BLUE);
  49.  
  50.   // bind em meia lua o angulo Γ© proporcional a 0 ..180+rotate=180.0+1.5
  51.   int angulo = map(velocidade, 0, 180, 0, 180); //mapa proprocional
  52.   float radianos = radians(angulo);  //radiano proprocional ao angulo
  53.  
  54.   // cordenada da line
  55.   int xPonteiro = centroX + raio * cos(radianos);
  56.   int yPonteiro = centroY + raio * sin(radianos);
  57.  
  58.   // Desenho o ponteiro. (:)
  59.   tft.drawLine(centroX, centroY, xPonteiro, yPonteiro, ST7735_RED);
  60. }
Advertisement
Add Comment
Please, Sign In to add comment