P-Comp // Wings!

This week Luna and I paired up for our Serial Communication assignment to make a pair of wings in P5.js that are controlled by a photoresistor:

It was a little tricky to get all the moving parts to work together (especially linking the serial port to our sketch), but Luna drew out the wings, I mapped out their up and down motion using a variable in P5, and we tackled mapping the wings’ path to the photoresistor / arduino together.

I also made a fading circle with the potentiometer 🙂

This feels like a breakthrough in physical computing for me because I’m finally able to incorporate digital content with these sensors, and I’ve never made anything on screen that’s truly interactive like this!

 

ICM // Peachy Hospital

Here’s me restructuring code by creating functions for each aspect of the visuals (also, the editor randomly named this “Peachy Hospital” which seems kind of perfect:

I was trying to figure out how to scale up the pawprints so it could randomly generate bigger or smaller ones, but this seemed almost impossible would grouping all of its components into one object (which I feel like I haven’t quite learned how to do yet?? maybe?) code below!

function setup() {
createCanvas(400, 400);
background(255, 230, 230);
}

function draw() {
squares();
}

function mousePressed() {
//background(255, 230, 230);
pawprint();
}

function pawprint() {
noStroke();
fill(random(100, 255), 0, random(100, 150), 100);
size = 8;
ellipse(mouseX, mouseY, size * 3, size * 3);
ellipse(mouseX + 18, mouseY – 5, size, size);
ellipse(mouseX + 12, mouseY – 15, size, size);
ellipse(mouseX, mouseY – 19, size, size);
ellipse(mouseX – 12, mouseY – 15, size, size);
}

function squares() {
noFill();
let color1 = map(mouseY, height, 0, 0, 255);
let color2 = map(mouseX, 0, width, 0, 255);
stroke(color1, color2, color1);

for (let y = height + 8; y >= mouseY; y -= 25) {
for (let x = 7; x <= mouseX; x += 25) {
rect(x, y, 10, 10);
}
}
}

P-Comp // Violin Tuner

So this week I attempted to make a tuner for string instruments with a 440A. This tuner was specifically meant for violin beginners, so the four buttons correspond to the E string, A string, D string, and G string. HOWEVER, as the video demonstrates below, I had some issues getting the A, D, and G buttons to play a clean sound.  I know this isn’t an issue with the speaker, as I tried just playing a note without using the buttons through it, but for some reason, the E button is the only one working (and even that one doesn’t produce the best sound). ¯\_(ツ)_/¯

I’d like to figure out why this is happening and how to fix it. Updates to follow. Here’s my code and a better photo because I think it has something to do with my wiring of it:

#include "pitches.h"

int input_g = 7, input_d = 8, input_a = 9, input_e = 10;
int output_g = 2, output_d = 3, output_a = 4, output_e = 5;
int tonePin = 6;
int e, a, d, g;

void setup() {
  Serial.begin(9600);
  pinMode(output_g, OUTPUT);
  pinMode(output_d, OUTPUT);
  pinMode(output_a, OUTPUT);
  pinMode(output_e, OUTPUT);

  pinMode(input_g, INPUT);
  pinMode(input_d, INPUT);
  pinMode(input_a, INPUT);
  pinMode(input_e, INPUT);

  pinMode(tonePin, OUTPUT);
}

void loop() { 
  g = digitalRead(input_g); 
  d = digitalRead(input_d);
  a = digitalRead(input_a);
  e = digitalRead(input_e);

if (g == HIGH) {
  //NOTE_G3
  digitalWrite(output_g, HIGH);
} else {
  digitalWrite(output_g, LOW);
  }

   if (g==HIGH) {
      tone(tonePin, NOTE_E5);
   } else {
    noTone(tonePin);
   }

if (d == HIGH) {
  //NOTE_D4
  digitalWrite(output_d, HIGH);
} else {
  digitalWrite(output_d, LOW);
}
  if (d==HIGH) {
    tone(tonePin, NOTE_E5);
  } else {
   noTone(tonePin);
  }


if (a == HIGH) {
  //NOTE_A4
  digitalWrite(output_a, HIGH);
} else {
  digitalWrite(output_a, LOW);
}
  if (a == HIGH) {
    tone(tonePin, NOTE_A4);
  } else {
    noTone(tonePin);
  }

if (e == HIGH) {
  //NOTE_E5
  digitalWrite(output_e, HIGH);
} else {
  digitalWrite(output_e, LOW);
}
  if (e == HIGH) {
    tone(tonePin, NOTE_E5);
  } else {
    noTone(tonePin);
  }

//tone(12, NOTE_A4);


  Serial.println(String(g) + " - " + String(d) + " - " + String(a) + " - " + String(e));

}