Lucky Cat Wave

I simplified my original plan and instead created a cat that waves to grant your wishes! For my setup, the microcontroller (server) returns a physical response (the cat waving) upon the browser’s (client) request.

Just submit your wish through the form on the browser UI and the lucky cat will wave for each character in your wish to grant it 🙂

In terms of the interaction, the command “Make a wish!” would prompt the user to enter his/her wish. Upon clicking the “Wish it” button (which affords clicking/pressing), the prompt returns a feedback “Wishing for _______ ?”. In addition to this, the “bell” attached to the cat’s collar would light up while its right paw waves. Once the waving is done, the light goes out.

The light as a signifier was helpful when I was first testing the servo on the cat. Because I put the ledOn and ledOff commands before and after the servo command, I could tell whether the servo was responding without waiting on it forever. As for the physical cat, I used a combination of modeling clay (everything but the arm) and Play Doh (just the arm). My guess is that the servo wouldn’t move because the clay arm was too heavy.

It works 🙂
let url = "http://192.168.1.106/"; // string to hold URL
let servoVal = 0; // variable that holds the servoVal
let input = "";
let button, greeting, wish;

//function preload() {
//  // Ensure the .ttf or .otf font stored in the assets directory
//  // is loaded before setup() and draw() are called
//  font = loadFont('assets/MADE Evolve Sans Bold (PERSONAL USE).otf');
//}

function setup() {
  createCanvas(windowWidth, windowHeight);
  frameRate(10);
  
  input = createInput();
  input.position(300, 405);

  button = createButton('Wish it');
  button.position(input.x + input.width + 5, 405);

  greeting = createElement('h1', 'Make a wish!'); // works because of the p5 dom library!
  greeting.position(300, 345);

  textSize(120);
  
  button.mousePressed(load);
  const wish = input.value();

}

function draw() {
  background(255, 204, 0);
}

function load() {
  let ledMode = "mode/4/o";
  console.log(url+ledMode);
  httpGet(url+ledMode, 'json');

  wish = input.value();
  console.log(wish);
  if (wish!=""){
    let ledOn = "digital/4/1";
    console.log(url+ledOn);
    httpGet(url+ledOn, 'json');
    greeting.html('Wishing for ' + wish + ' ?');
    input.value('');
    servoPos();
  }
  else {
      greeting.html('Make a wish!');
  }
}

function servoPos() {
  console.log('servoPos function works');
  servoVal= wish.length;
  let cmd;
  servoCmd ="servo?params=";
  httpGet(url+servoCmd+servoVal, 'json');
  console.log(url+servoCmd+servoVal);
  let ledOff = "digital/4/0";
  console.log(url+ledOff);
  httpGet(url+ledOff, 'json');
}