xxxxxxxxxx
139
dir = 0;
dir = 1;
dir = 2;
dir = 3;
dir = 4;
createP(speechRec.resultString);
if (speechRec.resultString.toLowerCase().includes("right")) {
}
} else if (speechRec.resultString.toLowerCase().includes("backward")) {
} else if (speechRec.resultString.toLowerCase().includes("forward")) {
} else if (speechRec.resultString.toLowerCase().includes("left")) {
} else if (speechRec.resultString.toLowerCase().includes("stop")) {
// make sure there is actually a message
// split the message
//////////////////////////////////
//////////////////////////////////
//SEND TO ARDUINO HERE (handshake)
console,log("Speech")
console.log(dir);
console.log(fromArduino[0]);
if (fromArduino.length == 1) {
if (speechRec.resultValue) {
image(speakImg, 180, 210, 100, 70);
isSpeaking = false;
let continuous = true;
let interim = false;
let sendToArduino= dir + "\n";
noStroke(); // No stroke for stop
robotX+=0.5
robotX-=0.5
robotY+=0.5
robotY-=0.5
setUpSerial();
speechRec.start(continuous, interim);
stroke(0, 0, 255); // Blue stroke for forward
stroke(0, 255, 0); // Green stroke for left
stroke(255, 0, 0); // Red stroke for right
stroke(255, 255, 0); // Yellow stroke for backward
text("Connected", 3400, 380);
text("Press Space Bar to select Serial Port", 340, 380);
writeSerial(sendToArduino);
}
let fromArduino = split(trim(data), ",");
}
////////////////////////////////////
////////////////////////////////////
//READ FROM ARDUINO HERE
background("rgb(244,227,68)");
createCanvas(600, 400);
ellipse(robotX, robotY, 20, 20);
ellipse(robotX, robotY, 30, 30);
else if (dir==2 && robotX > 360){
else if (dir==3 && robotY > 60){
else if (dir==4 && robotY < height-70 ){
fill(0);
fill(124,185,239)
fill(255);
function gotSpeech() {
if (!serialActive) {
if (data != null) {
if (dir == 1) {
if (dir==1 && robotX < width - 40){
if (isSpeaking) {
if (key == " ") {
image(img1,30,140,170,260)
image(title,30,20,300,180)
img1=loadImage("img.png")
isSpeaking = true;
let lang = navigator.language || "en-US";
let speech = new p5.Speech();
noFill()
rect(340,40,240,310)
robotX = 460;
robotY = 195;
speakImg=loadImage("speak.png")
speech.onEnd = () => {
speech.speak('Hi there!,This is your walking buddy. Join me to explore the world on foot. Use the commands Right, Left, Forward, Backward and Stop to navigate the directions. Finally, remember to stop when you hear the siren.')
speechRec = new p5.SpeechRec(lang, gotSpeech);
stroke(0);
strokeWeight(2)
textSize(15);
title=loadImage("title.png")
}
}
}
}
}
}
}
}
}
}
} else if (dir == 2) {
} else if (dir == 3) {
} else if (dir == 4) {
} else {
} else {
};
// // We take the string we get from Arduino and explicitly
// // convert it to a number by using int()
// // do everything with those values in the main draw loop
// // e.g. "103" becomes 103
// // only store values here
// // if the right length, then proceed
function draw() {
function keyPressed() {
function preload(){ bhu8
function readSerial(data) {
function setup() {
let dir = 0;
let img1;
let robotX, robotY;
let speechRec;
let title;
}
}
}
}
}9