TEAM: Qingqing Zhou, Leticia Li, Youer Zhao
Input:
Time of Flight Distance Sensor: distance
Output:
Image and sounds
Time of Flight Distance Sensor
Code on Arduino:
#include "Adafruit_VL53L0X.h"
#include "Wire.h"
//#include <Adafruit_VL53L0X.h>
Adafruit_VL53L0X lox = Adafruit_VL53L0X();
//const byte ledPin1 = 2;
//const byte ledPin2 = 3;
//const byte ledPin3 = 4;
int distance = 0;
int x = 0;
void setup() {
Serial.begin(9600);
Wire.begin();
//pinMode(ledPin1, OUTPUT);
//pinMode(ledPin2, OUTPUT);
//pinMode(ledPin3, OUTPUT);
Serial.println("Adafruit VL53L0X test");
if (!lox.begin()) {
Serial.println(F("Failed to boot VL53L0X"));
while(1);
}
// power
Serial.println(F("VL53L0X API Simple Ranging example\\n\\n"));
}
void loop() {
VL53L0X_RangingMeasurementData_t measure;
distance = measure.RangeMilliMeter;
int x = Serial.read();
// Serial.print("Reading a measurement... ");
lox.rangingTest(&measure, false); // pass in 'true' to get debug data printout!
// prestep
if (distance > 1000) {
x = 0;
Serial.println(x);
delay(5);
}
// step 1_ flower growing, closer
if (distance >= 830 && distance <= 980) {
x = 1;
Serial.println(x);
delay(5);
}
//step 2 closer
if (distance <= 600 && distance > 500) {
x = 2;
Serial.println(x);
delay(5);
}
//step 3 grab me
if (distance < 300 && distance >= 200) {
x = 3;
Serial.println(x);
delay(5);
}
//step 4 hello, welcome
if (distance < 80) {
x = 4;
Serial.println(x);
delay(5);
}
}
Code on P5:
let serial; // variable to hold an instance of the serialport library
let portName = 'COM6'; // replace with your own port
let correctData;
//let vid0;
let vid1;
let vid2;
let vid3;
//let vid4;
//let audio0;
let audio1;
let audio2;
let audio3;
let playing = true;
function setup() {
createCanvas(800, 600);
background(0);
// Serial setup
serial = new p5.SerialPort(); // make a new instance of the serialport library
serial.on('list', printList); // callback to list all the ports
serial.on('connected', serverConnected); // callback for connecting to server
serial.on('open', portOpen); // callback to check port opening
serial.on('data', serialEvent); // callback for when new data arrives
serial.on('error', serialError); // callback for errors
serial.on('close', portClose); // callback for the port closing
serial.list(); // list the serial ports
serial.open(portName); // open a serial port
// vid0 = createVideo("prestep_1.mp4");
vid1 = createVideo("STEP1.mp4");
vid2 = createVideo("STEP2.mp4");
vid3 = createVideo("STEP3.mp4");
// audio0 = createAudio("prestep_1.mp3");
audio1 = createAudio("1.m4a");
audio2 = createAudio("2.m4a");
audio3 = createAudio("3.m4a");
// V 0
// vid0.size(800, 600);
// audio0.volume(0);
// vid0.loop();
// vid0.hide(); // hides the html video loader
// V 1
vid1.size(800, 600);
// audio1.volume(0);
vid1.loop();
vid1.hide(); // hides the html video loader
// V 2
vid2.size(800, 600);
vid2.loop();
// audio2.volume(0);
vid2.hide(); // hides the html video loader
// V 3
vid3.size(800, 600);
// audio3.volume(0);
vid3.loop();
vid3.hide(); // hides the html video loader
}
function draw() {
// Use clear() to erase the previous drawings
clear();
//pre-step, soundover
// if (correctData == 0) {
// if (vid0.elt.readyState >= 4) {
// vid0.play();
// let img0 = vid0.get();
// image(img0, 0, 0);
// }
// }
//step 1, flower growing, closer
if (correctData == 1 ) {
if (vid1.elt.readyState >= 4) {
vid1.play();
audio1.play();
let img1 = vid1.get();
image(img1, 0, 0);
}
}
//step 2, closer
if (correctData == 2) {
if (vid2.elt.readyState >= 4 ) {
vid2.play();
audio2.play();
let img2 = vid2.get();
image(img2, 0, 0);
}
}
//step 3, raising your hand
if (correctData == 3) {
if (vid3.elt.readyState >= 4) {
vid3.play();
audio3.play();
let img3 = vid3.get();
image(img3, 0, 0);
}
}
playing = !playing
}