> #include <Wire.h>
> #include <Arduino_LSM9DS1.h>
> #include <SparkFun_VEML6030_Ambient_Light_Sensor.h>
> #include <VL53L1X.h>
>
>
> #define VL53L1X_sensor 0x29
> VL53L1X sensor (VL53L1X_sensor);
>
>
> const unsigned long StandingStillInterval = 5000;
>
> const float MagnitudeThreshhold = 0.1; // Determine by experiment
>
> float x, y, z;
> float oldX, oldY, oldZ;
> long IsStill = false; // board movement setting
>
> static unsigned long timeLastMoved = 0;
>
> float degreesX = 0;
> float degreesY = 0;
> float degreesZ = 0;
>
>
> #define buzzerpos D7 //D3 buzzer output
>
> #define motorPin D3 //vibrator motor output
> int SW1 = 0;
>
> #define AL_ADDR 0x48
> SparkFun_Ambient_Light light(AL_ADDR);
>
> // Possible values: .125, .25, 1, 2
> // Both .125 and .25 should be used in most cases except darker rooms.
> // A gain of 2 should only be used if the sensor will be covered by a dark
> // glass.
> float gain = .125;
>
> // Possible integration times in milliseconds: 800, 400, 200, 100, 50, 25
> // Higher times give higher resolutions and should be used in darker light.
> int time = 100;
> long luxVal = 0;
>
> void setup() {
> {
> Serial.begin(9600);
> while (!Serial);
> Serial.println("Started");
>
> if (!IMU.begin())
> {
> Serial.println("Failed to initialize IMU!");
> while (1);
> }
>
> Serial.print("Accelerometer sample rate = ");
> Serial.print(IMU.accelerationSampleRate());
> Serial.println("Hz");
> }
>
> {
> Serial.begin(115200);
> Wire.begin();
> Wire.setClock(400000); // use 400 kHz I2C
>
> sensor.setTimeout(500);
> if (!sensor.init())
> {
> Serial.println("Failed to detect and initialize sensor!");
> while (1);
> }
>
>
> // Use long distance mode and allow up to 50000 us (50 ms) for a measurement.
> // You can change these settings to adjust the performance of the sensor, but
> // the minimum timing budget is 20 ms for short distance mode and 33 ms for
> // medium and long distance modes. See the VL53L1X datasheet for more
> // information on range and timing limits.
> sensor.setDistanceMode(VL53L1X::Long);
> sensor.setMeasurementTimingBudget(33000);
>
> // Start continuous readings at a rate of one measurement every 50 ms (the
> // inter-measurement period). This period should be at least as long as the
> // timing budget.
> sensor.startContinuous(50);
> }
>
> {
> if (light.begin())
> Serial.println("Ready to sense some light!");
> else
> Serial.println("Could not communicate with the sensor!");
>
> // Again the gain and integration times determine the resolution of the lux
> // value, and give different ranges of possible light readings. Check out
> // hoookup guide for more info.
> light.setGain(gain);
> light.setIntegTime(time);
>
> Serial.println("Reading settings...");
> Serial.print("Gain: ");
> float gainVal = light.readGain();
> Serial.print(gainVal, 3);
> Serial.print(" Integration Time: ");
> int timeVal = light.readIntegTime();
> Serial.println(timeVal);
>
> }
> }
>
> void loop()
> {
>
> if (HasMoved())
> {
> timeLastMoved = millis();
> if (millis() - timeLastMoved < StandingStillInterval)
> {
> IsStill = false;
> Serial.print("Started moving again at ");
> Serial.println(timeLastMoved);
> }
> }
>
> if (millis() - timeLastMoved > StandingStillInterval)
> {
> if (!IsStill)
> {
> IsStill = true;
> Serial.print("Stopped moving at ");
> Serial.println(timeLastMoved);
>
> Serial.print("Has been still for 2 seconds at ");
> Serial.println(millis());
>
> }
>
> }
>
>
> // Move eyes whenever not still
> if (!IsStill)
> { Eyes();
> }
> }
> float square(const float f)
> {
> return f * f;
> }
>
> boolean HasMoved()
> {
> if (!IMU.accelerationAvailable())
> return false; // Can't tell if it has moved because data isn't available
>
> IMU.readAcceleration(x, y, z);
>
> float magnitudeOfChange = square(x - oldX) + square(y - oldY) + square(z - oldZ);
> //{ Serial.print("magnitude of change: ");
> //Serial.println(magnitudeOfChange);
> //}
> oldX = x;
> oldY = y;
> oldZ = z;
>
> return magnitudeOfChange > MagnitudeThreshhold; //measurement of board movement and comparing if greater than Magnitude Threshhold
> }
>
> /*==============================================
> Electronic eyes
> ===================================================*/
> void Eyes()
> {
> if (HasMoved())
> ( IsStill == false);
> { Serial.println(" Started eyes scanning ");
> Serial.println(timeLastMoved);
> }
> if (IMU.accelerationAvailable())
>
> IMU.readAcceleration( x, y, z );
>
> float fx, fy, fz;
>
>
> /*==============================================
> //Angle Measurment code
> ===================================================*/
>
>
> if (x > 0.1) //activate angle measurement if within set boundaries
> {
> fx = x * 100;
> degreesX = map(fx, 0, 97, 0, 90);
> Serial.print(" Tilting up ");
> Serial.print(degreesX);
> Serial.println(" degrees");
> delay(500);
> }
>
> if (x < -0.1)
> {
> fx = x * 100;
> degreesX = map(fx, 0, -100, 0, 90);
> Serial.print("Tilting down ");
> Serial.print(degreesX);
> Serial.println(" degrees");
> delay(500);
> }
>
> if (y > 0.1)
> {
> fy = y * 100;
> degreesY = map(fy, 0, 97, 0, 90);
> Serial.print("Tilting left ");
> Serial.print(degreesY);
> Serial.println(" degrees");
> delay(500);
> }
>
> if (y < -0.1)
> {
> fy = y * 100;
> degreesY = map(fy, 0, -100, 0, 90);
> Serial.print("Tilting right ");
> Serial.print(degreesY);
> Serial.println(" degrees");
> delay(500);
> }
>
> if (z > 0.1)
> {
> fz = z * 100;
> degreesZ = map(fz, 0, 97, 0, 90);
> // Serial.print(" Tilting up ");
> // Serial.print(degreesZ);
> // Serial.println(" degrees");
> // delay(500);
> }
>
> if (z < -0.1)
> {
> fz = z * 100;
> degreesZ = map(fz, 0, -100, 0, 90);
> // Serial.print("Tilting down ");
> // Serial.print(degreesZ);
> // Serial.println(" degrees");
> // delay(500);
> }
>
>
> /*==============================================
> VL53L1X Laser measurement
> ===================================================*/
> if (IsStill == false)
> {
> {
> sensor.read();
>
> /*==============================================
> Print Laser measurment to Serial Monitor
> ===================================================*/
>
>
>
> Serial.print("range: ");
> Serial.print(sensor.ranging_data.range_mm);
> Serial.print("\tstatus: ");
> Serial.print(VL53L1X::rangeStatusToString(sensor.ranging_data.range_status));
> Serial.print("\tpeak signal: ");
> Serial.print(sensor.ranging_data.peak_signal_count_rate_MCPS);
> Serial.print("\tambient: ");
> Serial.print(sensor.ranging_data.ambient_count_rate_MCPS);
>
> Serial.println();
> }
>
>
> /*==========================================
> Control Buzzer and Vibrator Motor
> ================ ==================================*/
>
>
> { Serial.print(" Moving and now measuring distance ");
> }
>
> if (sensor.ranging_data.range_mm > 150 && sensor.ranging_data.range_mm < 255) //these statements activate when true the related switch
> {
> SW1 = 1; //STOP, SLOW
> }
> else if (sensor.ranging_data.range_mm > 260 && sensor.ranging_data.range_mm < 355)
> {
> SW1 = 2; //STOP,SLOW,SLOW
> }
> else if (sensor.ranging_data.range_mm > 360 && sensor.ranging_data.range_mm < 755)
> {
> SW1 = 3; //SLOW
> }
> else if (sensor.ranging_data.range_mm > 760 && sensor.ranging_data.range_mm < 1000)
> {
> SW1 = 4; //Just vibrator motor
> }
>
> else {
> SW1 = 0;
> }
>
> switch (SW1) {
> case 1:
> // Serial.println(" Case 1 ");
> digitalWrite(D7, 255);
> tone(D7, 5000, 500); // tone on pin 8 at 40000 Hz for 0.1 second
> digitalWrite(D7, 0);
> delay(100); //sound buzzer every second if obstacle distance is between 20-30cm.
> digitalWrite(motorPin, HIGH); //vibrator buzzer on
> delay (100);
> digitalWrite(motorPin, LOW); //vibrator buzzer off
> delay(100);
> Serial.println(" Case 1 ");
> delay (500);
> break;
>
>
>
>
> case 2:
> // Serial.println(" Case 2 ");
> digitalWrite(D7, 255);
> tone(D7, 3000, 300); // tone on pin 8 at 35000 Hz for 0.1 second
> digitalWrite(D7, 0);
> delay(300); //sound buzzer every 0.5 seconds if obstacle distance is between 10-20cm.
> digitalWrite(motorPin, HIGH);
> delay (350);
> digitalWrite(motorPin, LOW);
> delay(350);
> Serial.println(" Case 2 ");
> delay (1000);
> break;
>
>
>
>
>
> case 3:
> // Serial.println(" Case 3 ");
> digitalWrite(D7, 255);
> tone(D7, 2000, 200); // tone on pin 8 at 30000 Hz for 0.2 second
> digitalWrite(D7, 0);
> delay(500); //sound buzzer every 0.5 seconds if obstacle distance is between 10-20cm.
> digitalWrite(motorPin, HIGH);
> delay (250);
> digitalWrite(motorPin, LOW);
> delay(250);
> Serial.println(" Case 3 ");
> delay (1500);
> break;
>
>
>
>
> case 4:
> // Serial.println(" Case 4 ");
> digitalWrite(D7, 255);
> tone(D7, 1000, 100); // tone on pin 8 at 25000 Hz for 0.3 second
> digitalWrite(D7, 0);
> delay(700); //sound buzzer every 0.1 seconds if obstacle distance is between 0-10cm.
> digitalWrite(motorPin, HIGH);
> delay (100);
> digitalWrite(motorPin, LOW);
> delay(100);
> Serial.println(" Case 4 ");
> delay (2000);
> break;
>
>
> case 0:
> // Serial.println(" Case 0 ");
> digitalWrite(D7, 0); //do not sound the buzzer
> Serial.println(" Case 0 ");
> break;
>
> default:
> //Serial.println(" SCdefault! ");
> digitalWrite(D7, 0); //do not sound the buzzer
> Serial.println(" SCdefault! ");
> break;
>
> }
>
>
> /*==========================================
> Control LED locator
> ==================================================*/
>
> {
> luxVal = light.readLight();
> Serial.print("Ambient Light Reading: ");
> Serial.print(luxVal);
> Serial.println(" Lux");
> delay(1000);
> }
> if (luxVal >= 10);
> {digitalWrite(D2, 255);
> delay (1000);}
> else {digitalWrite(D2, 0);
> }
> }
> }
Errors:
Arduino: 1.8.16 (Windows Store 1.8.51.0) (Windows 10), Board: "Arduino Nano 33 BLE"
Cyclops_V1.1:6:31: error: no matching function for call to 'VL53L1X::VL53L1X(int)'
VL53L1X sensor (VL53L1X_sensor);
^
In file included from C:\Users\KevB\Documents\Arduino\Cyclops\Cyclops_V1.1\Cyclops_V1.1.ino:4:0:
C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master/VL53L1X.h:1273:5: note: candidate: VL53L1X::VL53L1X()
VL53L1X();
^~~~~~~
C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master/VL53L1X.h:1273:5: note: candidate expects 0 arguments, 1 provided
In file included from C:\Users\KevB\Documents\Arduino\Cyclops\Cyclops_V1.1\Cyclops_V1.1.ino:4:0:
C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master/VL53L1X.h:6:7: note: candidate: constexpr VL53L1X::VL53L1X(const VL53L1X&)
class VL53L1X
^~~~~~~
C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master/VL53L1X.h:6:7: note: no known conversion for argument 1 from 'int' to 'const VL53L1X&'
C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master/VL53L1X.h:6:7: note: candidate: constexpr VL53L1X::VL53L1X(VL53L1X&&)
C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master/VL53L1X.h:6:7: note: no known conversion for argument 1 from 'int' to 'VL53L1X&&'
Cyclops_V1.1:40:5: error: 'int time' redeclared as different kind of symbol
int time = 100;
^~~~
In file included from c:\users\kevb\documents\arduinodata\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\arm-none-eabi\include\stdio.h:29:0,
from C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\cores\arduino/mbed/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/components/libraries/util/app_error.h:54,
from C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\cores\arduino/mbed/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/components/libraries/util/app_util_platform.h:60,
from C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\cores\arduino/mbed/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/integration/nrfx/nrfx_glue.h:182,
from C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\cores\arduino/mbed/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/modules/nrfx/nrfx.h:46,
from C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\cores\arduino/mbed/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/modules/nrfx/hal/nrf_gpio.h:44,
from C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\cores\arduino/mbed/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/TARGET_ARDUINO_NANO33BLE/PinNames.h:23,
from C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\variants\ARDUINO_NANO33BLE/pinmode_arduino.h:17,
from C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\cores\arduino/Arduino.h:26,
from sketch\Cyclops_V1.1.ino.cpp:1:
c:\users\kevb\documents\arduinodata\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\arm-none-eabi\include\time.h:59:11: note: previous declaration 'time_t time(time_t*)'
time_t _EXFUN(time, (time_t *_timer));
^
C:\Users\KevB\Documents\Arduino\Cyclops\Cyclops_V1.1\Cyclops_V1.1.ino: In function 'void setup()':
Cyclops_V1.1:97:28: error: invalid conversion from 'time_t (*)(time_t*) {aka long long int (*)(long long int*)}' to 'uint16_t {aka short unsigned int}' [-fpermissive]
light.setIntegTime(time);
^
In file included from C:\Users\KevB\Documents\Arduino\Cyclops\Cyclops_V1.1\Cyclops_V1.1.ino:3:0:
C:\Users\KevB\Documents\Arduino\libraries\SparkFun_Ambient_Light_Sensor_Arduino_Library-master\src/SparkFun_VEML6030_Ambient_Light_Sensor.h:95:10: note: initializing argument 1 of 'void SparkFun_Ambient_Light::setIntegTime(uint16_t)'
void setIntegTime(uint16_t time);
^~~~~~~~~~~~
C:\Users\KevB\Documents\Arduino\Cyclops\Cyclops_V1.1\Cyclops_V1.1.ino: In function 'void Eyes()':
Cyclops_V1.1:404:4: error: expected '}' before 'else'
else {digitalWrite(D2, 0);
^~~~
C:\Users\KevB\Documents\Arduino\Cyclops\Cyclops_V1.1\Cyclops_V1.1.ino: At global scope:
Cyclops_V1.1:407:1: error: expected declaration before '}' token
}
^
exit status 1
no matching function for call to 'VL53L1X::VL53L1X(int)'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.