// // hello.VL53L1x.ino // // VL53L1X hello-world // Pololu library // // Neil Gershenfeld 10/31/20 // // This work may be reproduced, modified, distributed, // performed, and displayed for any purpose, but must // acknowledge this project. Copyright is retained and // must be preserved. The work is provided as is; no // warranty is provided, and users accept all liability. // #include #include #include VL53L1X device; #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) // The pins for I2C are defined by the Wire-library. // On an arduino UNO: A4(SDA), A5(SCL) // On an arduino MEGA 2560: 20(SDA), 21(SCL) // On an arduino LEONARDO: 2(SDA), 3(SCL), ... #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) #define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire1, OLED_RESET); bool success = false; void setup() { // // set up serial // pinMode(5,OUTPUT); digitalWrite(5,HIGH); Serial.begin(115200); // // set up I2C // Wire.begin(); Wire.setClock(400000); // // set up VL53L1X // device.setTimeout(500); // device.setBus(&Wire); success = device.init(); device.setDistanceMode(VL53L1X::Long); device.setMeasurementTimingBudget(140000); device.startContinuous(140); // set up SSD1306 // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1306 allocation failed")); for(;;); // Don't proceed, loop forever } display.display(); //testdrawbitmap(); //adafruit sample code SHlogo(); } void loop() { // // read VL53L1X // device.read(); uint16_t distanceread = device.readRangeSingleMillimeters(); Serial.print(distanceread); Serial.println(" mm"); readdistance(distanceread); delay(50); } //code for the OLED to display the LASER TOF sensor distance void readdistance(uint16_t sensor) { display.clearDisplay(); display.setTextSize(3); // Normal 1:1 pixel scale display.setTextColor(SSD1306_WHITE); // Draw white text display.setCursor(0, 0); // Start at top-left corner display.cp437(true); // Use full 256 char 'Code Page 437' font // Not all the characters will fit on the display. This is normal. // Library will draw what it can and the rest will be clipped. display.print(sensor); display.print(" mm"); display.display(); //delay(2000); } //code to display my car's logo void SHlogo(void) { display.clearDisplay(); display.setTextSize(3); // Normal 1:1 pixel scale display.setTextColor(SSD1306_WHITE); // Draw white text display.setCursor(10, 10); // Start at center display.cp437(true); // Use full 256 char 'Code Page 437' font // Drawing my name logo display.print("SH"); display.display(); display.startscrolldiagright(0x00, 0x07); delay(2000); display.startscrolldiagleft(0x00, 0x07); delay(2000); display.stopscroll(); delay(1000); }