kalibre

bolhasanim

Mar 25th, 2024
1,152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 2.31 KB | Software | 0 0
  1. //bem10jfx.blogspot.com.br
  2.  
  3. #include <Adafruit_GFX.h>    // Biblioteca
  4. #include <Adafruit_ST7735.h> // Adafruit
  5. // Definindo os pinos do display
  6. #define TFT_CS     10 // CS
  7. #define TFT_RST    8  // Reset//referente ao loop();eviatar
  8. #define TFT_DC     9 // DC
  9.  Adafruit_ST7735 tft = Adafruit_ST7735(10,  9, 8);
  10.  int  BIND_WIDTH = 128; //pixels
  11.  int BIND_HEIGHT = 160;//pixels
  12.  int int_Lx = tft.width() / 2;  //binda da tela dividada
  13.  int int_Ly = tft.height() / 2;
  14.  int engate_velX = 1; //velocidades orizontal
  15.  int engate_velY = 2 ; // velocidade vertical
  16.  int vlx=0;
  17.  int RADIAL = 5; // Raio do círculo
  18.  
  19. void setup() {
  20.    tft.initR(INITR_BLACKTAB); // Initializaçao....
  21.   //display black
  22.   tft.fillScreen(ST7735_BLACK);
  23.   tft.drawCircle(int_Lx, int_Ly, RADIAL, ST7735_BLUE);
  24.   programa();}
  25.  
  26. void loop() {}; //evitar
  27. void programa(){
  28.    int_Lx += engate_velX; //valores com diferencia de potencial :D
  29.    int_Ly += engate_velY;
  30.  
  31.   // Verificar limites da tela
  32.   //  se a localizaçao do objeto x + o radial do cirle for o maior que o limite de pixel e se a
  33.   // localizaçao for menor ou igual o liminite minimo da tela
  34.    if (int_Lx + RADIAL > BIND_WIDTH || int_Lx - RADIAL < 0) {
  35.      engate_velX = -engate_velX; // utilize o valor atual  diminuindo ou almentando dependendo da direçao e do limite
  36.      legacy(); //imprime uma bolha com cor diferente na nos limites do layout
  37.   }
  38.  
  39.   if (int_Ly + RADIAL > BIND_HEIGHT || int_Ly - RADIAL < 0) {
  40.     engate_velY = -engate_velY; // heigth
  41.     legacy();//imprime uma bolha com cor diferente na nos limites do layout
  42.   }
  43.        
  44.   // sobrepor mesma cor do backgraund
  45.   tft.drawCircle(int_Lx - engate_velX, int_Ly - engate_velY, RADIAL, ST7735_BLACK);
  46.    legacy();
  47.    delay(120);
  48.    loop2();//passa pra oloop 2 e o loop2 manda devolta pra o programa sem utilizar oreset do void loop();
  49. }
  50. void loop2(){
  51.    programa();
  52.    delay(20);
  53.   };
  54.   void legacy(){
  55.    if(vlx==0){  // criar
  56.    tft.drawCircle(int_Lx, int_Ly, RADIAL, ST7735_BLUE);
  57.    vlx=vlx+1;
  58. }else  if(vlx==1){
  59.    tft.drawCircle(int_Lx, int_Ly, RADIAL, ST7735_RED);
  60.    vlx=2;
  61.     }else if(vlx==2){  // criar
  62.      tft.drawCircle(int_Lx, int_Ly, RADIAL, ST7735_YELLOW);
  63.      vlx=3;
  64.      }else if(vlx==3){  // criar
  65.       tft.drawCircle(int_Lx, int_Ly, RADIAL, ST7735_WHITE);
  66.        vlx=0;
  67. }
  68.   }
Advertisement
Add Comment
Please, Sign In to add comment