Code: Select all
#include <Adafruit_VL53L1X.h>
#include <ComponentObject.h>
#include <RangeSensor.h>
#include <vl53l1x_class.h>
#include <vl53l1x_error_codes.h>
#include <Adafruit_NeoPixel.h>
#define IRQ_PIN 2
#define XSHUT_PIN 3
Adafruit_VL53L1X vl53 = Adafruit_VL53L1X(XSHUT_PIN, IRQ_PIN);
// How many internal neopixels do we have? some boards have more than one!
#define NUMPIXELS 1
Adafruit_NeoPixel pixels(NUMPIXELS, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800);
int unoccupiedOutput = A0; //this controls the relay for unoccupied output
int occupiedOutput = A1; //this controls the relay for occupied output
int setupButton = A2; //this is the input for the setup button
int pot = A3; //this is the input for the potentiometer
int occupiedStatus = SDA; //this reads the status of the relay
int energizeTime = 250; //this is the length of time we energize the relay in milliseconds
int spaceStatusPeriod = 500; //this is how long the PIXEL will be lit to show space status
int sleepPeriod = 150000; //duration of sleep between runs of the program (sleep period in milliseconds)
void setup() {
Serial.begin(115200);
delay(5000);
Serial.println("setup started");
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
pixels.setBrightness(20); // not so bright
//let set the relay output pin modes
pinMode(unoccupiedOutput,OUTPUT); //changes relay to unoccupied
pinMode(occupiedOutput,OUTPUT);//changes relay to occupied
pinMode(occupiedStatus,INPUT_PULLDOWN); //this pin tells us the status of the relay. It's like retained memory this pin is the potentiometer
Wire.begin();
Serial.println("we're past Wire.begin()");
if (!vl53.begin(0x29, &Wire)) {
Serial.println("we're in the !vl53.begin if statement");
Serial.print(F("Error on init of VL sensor: "));
Serial.println(vl53.vl_status);
delay(2000);
while (1) delay(10);
}
Serial.println(F("VL53L1X sensor OK!"));
Serial.print(F("Sensor ID: 0x"));
Serial.println(vl53.sensorID(), HEX);
if (! vl53.startRanging()) {
Serial.print(F("Couldn't start ranging: "));
Serial.println(vl53.vl_status);
while (1) delay(10);
}
Serial.println(F("Ranging started"));
// Valid timing budgets: 15, 20, 33, 50, 100, 200 and 500ms!
vl53.setTimingBudget(50);
Serial.print(F("Timing budget (ms): "));
Serial.println(vl53.getTimingBudget());
}
// the loop routine runs over and over again forever:
void loop() {
// say hi
Serial.println("Hello!");
// set color to red/green/blue
pixels.fill(0xFF0000);
pixels.show();
digitalWrite(A0,HIGH);
delay(1000); // wait half a second
// turn off
pixels.fill(0x000000);
pixels.show();
digitalWrite(A0,LOW);
delay(1000); // wait half a second
// set color to red/green/blue
pixels.fill(0x00FF00);
pixels.show();
digitalWrite(A1,HIGH);
delay(1000); // wait half a second
// turn off
pixels.fill(0x000000);
pixels.show();
digitalWrite(A1,LOW);
delay(1000); // wait half a second
int16_t distance;
// if (vl53.dataReady()) {
// // new measurement for the taking!
// distance = vl53.distance();
// if (distance == -1) {
// // something went wrong!
// Serial.print(F("Couldn't get distance: "));
// Serial.println(vl53.vl_status);
// return;
// }
// Serial.print(F("Distance: "));
// Serial.print(distance);
// Serial.println(" mm");
// // data is read out, time for another reading!
// vl53.clearInterrupt();
// }
}