Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // GOOD FOR ESP32CS DEV MODULE
- #include <Wire.h>
- #include <Adafruit_GC9A01A.h>
- #include <Adafruit_GFX.h>
- #include <VL53L0X.h>
- // Define the Pins for the Display
- #define TFT_CS 5 // Chip select pin
- #define TFT_RST 1 // Reset pin
- #define TFT_DC 0 // Data/Command pin
- int distance = 0;
- int radiusmap = 0;
- int centerX;
- int centerY;
- VL53L0X sensor;
- // Create an instance of the display
- Adafruit_GC9A01A tft = Adafruit_GC9A01A(TFT_CS, TFT_DC, TFT_RST);
- void setup() {
- Serial.begin(115200);
- Wire.setPins( 14, 15);
- Wire.begin();
- sensor.setTimeout(500);
- if (!sensor.init())
- {
- Serial.println("Failed to detect and initialize sensor!");
- while (1) {}
- }
- sensor.setTimeout(500);
- if (!sensor.init())
- {
- Serial.println("Failed to detect and initialize sensor!");
- while (1) {}
- }
- sensor.startContinuous();
- tft.begin(); // Initialize the display
- tft.setRotation(0); // Set the rotation of the display
- tft.fillScreen(GC9A01A_BLACK); // Fill the screen with black color
- // Draw a circle
- centerX = tft.width() / 2; // Center x of the display
- centerY = tft.height() / 2; // Center y of the display
- int diameter = 240;
- int radius = diameter/2;
- tft.drawCircle(centerX, centerY, radius-10, GC9A01A_RED);
- tft.setTextColor(GC9A01A_GREEN,GC9A01A_BLACK);
- tft.setTextSize(2);
- }
- void loop() {
- distance = sensor.readRangeContinuousMillimeters();
- if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
- Serial.println();
- if (distance > 500) {
- distance = 500;
- }
- Serial.println(distance);
- radiusmap = map(distance,0,500,0,120); //convert distance to radius
- tft.fillScreen(GC9A01A_BLACK); // Fill the screen with black color
- tft.drawCircle(centerX, centerY, radiusmap, GC9A01A_RED);
- tft.setTextColor(GC9A01A_GREEN,GC9A01A_BLACK);
- tft.setTextSize(2);
- tft.setCursor(105, 110); // Set cursor position
- tft.print(distance);
- delay(250);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement