Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- #include <Wire.h>
- #include <VL53L1X.h>
- Servo phiservo;
- Servo etaservo;
- VL53L1X sensor;
- int phi = 0;
- int eta = 0;
- int r[180];
- int i = 0;
- void excelAusgabe();
- void setup() {
- Serial.begin(2000000);
- // Serial.println("Setup gestartet!");
- Wire.begin();
- Wire.setClock(400000); // use 400 kHz I2C
- sensor.setTimeout(5000);
- if (!sensor.init())
- {
- Serial.println("Failed to detect and initialize sensor!");
- while (1);
- }
- sensor.setDistanceMode(VL53L1X::Long);
- sensor.setMeasurementTimingBudget(50000);
- //excelSetup();
- phiservo.attach(D3);
- phiservo.write(0);
- etaservo.attach(D4);
- etaservo.write(0);
- sensor.startContinuous(50);
- }
- void loop() {
- for (eta = 45; eta <= 135; eta += 1)
- {
- etaservo.write(eta); // tell servo to go to position in variable 'pos'
- delay(15);
- phi = 175;
- if (eta == 45)
- {
- Serial.print("warte auf eta...");
- Serial.println();
- delay(100);
- }
- i = 0;
- phiservo.write(175); // tell servo to go to position in variable 'pos'
- delay(500);
- for (phi = 175; phi >= 5; phi -= 1) // goes from 0 degrees to 180 degrees in steps of 1 degree
- {
- phiservo.write(phi); // tell servo to go to position in variable 'pos'
- delay(15);
- etaservo.write(eta); // tell servo to go to position in variable 'pos'
- while (sensor.dataReady() == false)
- {
- delay(1);
- }
- sensor.read();
- r[i] = sensor.ranging_data.range_mm;
- if (VL53L1X::rangeStatusToString(sensor.ranging_data.range_status) == "wrap target fail")
- {
- r[i] = 0;
- }
- else if (r[i] > 4000)
- {
- r[i] = 0;
- }
- else if (sensor.timeoutOccurred())
- {
- r[i] = 0;
- }
- // Serial.print(r[i]);
- // Serial.println();
- Serial.print(i);
- Serial.print(",");
- Serial.print(r[i]);
- Serial.println();
- i++;
- }
- //excelAusgabe();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment