Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //bem10jfx.blogspot.com
- #include <Adafruit_GFX.h>
- #include <Adafruit_ST7735.h>
- #define TFT_CS 10 //cs
- #define TFT_RST 12 //rebot
- #define TFT_DC 9 //sda
- Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST); //defs
- int velocidadefinal;
- void setup() {
- Serial.begin(9600);
- Serial.begin(9600);
- tft.setCursor(0,30); //HEIGH, WIDTH //y,x
- tft.initR(INITR_BLACKTAB); // TELAPRETA inicial?????????
- tft.setTextSize(1); // FONTALIGMENT 1
- tft.fillScreen(ST7735_BLACK); // color display
- tft.setTextColor(ST7735_BLUE); //cor de texto
- tft.print("Bem10jfx.blogspot.com"); //
- tft.setRotation(1.5);
- desenharVelocimetro(0); // Inicia o velocΓmetro com velocidade zero
- }
- void loop() {
- desenharVelocimetro(velocidadefinal);
- Serial.println(velocidadefinal);
- int velocidade = Serial.parseInt(); // LΓͺ a velocidadeserial
- if (Serial.available() > 0) {
- velocidadefinal=velocidade;//guarda o ultimo valor ate chegar o proximo
- desenharVelocimetro(velocidadefinal);
- }
- delay(100);
- }
- void desenharVelocimetro(int velocidade) {
- int centroX = tft.width() / 2;//bind do limite
- int centroY = tft.height() / 2;//de cordenadas do circle
- int raio = min(tft.width(), tft.height()) / 3; //na tela dividido por2
- tft.fillCircle(centroX, centroY, raio, ST7735_BLACK);
- tft.fillCircle(centroX, centroY, raio - 10, ST7735_BLUE);
- // bind em meia lua o angulo Γ© proporcional a 0 ..180+rotate=180.0+1.5
- int angulo = map(velocidade, 0, 180, 0, 180); //mapa proprocional
- float radianos = radians(angulo); //radiano proprocional ao angulo
- // cordenada da line
- int xPonteiro = centroX + raio * cos(radianos);
- int yPonteiro = centroY + raio * sin(radianos);
- // Desenho o ponteiro. (:)
- tft.drawLine(centroX, centroY, xPonteiro, yPonteiro, ST7735_RED);
- }
Advertisement
Add Comment
Please, Sign In to add comment