Final Project so far:

I have been looking into the machine learning library, and so far, I have achieved the poseNet creation for the palms but I am now looking into how this can be used to control my steering wheel. What steering wheel you might be wondering. So I have created a steering wheel that I plan to use to control the wheels of the car I would create. That is if I should choose to create a car. The p5 sketch for the steering wheel so far is below

So I continue to look into how to do the integration but for the ML so far this is what I have below:

Its not much but its cooking. Inshallah!

Alien Intelligence w/Professor Leach

 

I was so happy to attend Professor Leach’s talk about AI! The conversation of AI has recently come up in a discussion with some of my peers and it reminded me of a few of the topics that were discussed in Professor Leach’s talk. In conversation, we were discussing the role of AI in the arts and how AI can be quite harmful to artists, at least that’s what I believe. My friends disagreed (quite loudly if I may add) and maintained the stance that AI will never be able to create art in the same way a human can. They went on to say that you simply can’t program creativity, so AI would be unlikely to replace human artists.

Here are my thoughts.

As an artist myself, I feel that we are entering a very tricky time. For me, it isn’t about my art vs the AI-generated art. It’s more so these questions: Will people be able to tell the difference or care who made the art? Will art become devalued and seen as something that can be simply generated by AI? Why would you pay for artists and their work when you can recreate their work or make something even more artificially “perfect” with AI?

These questions have yet to be answered and are quite difficult to answer. I wonder what the future will look like for artists who ultimately will have to compete with not only other artists like themselves, but AI as well.

 

FINAL PROJECT PROPOSAL

For my final project, I wanted to do something that was related to sound since I have a great interest in all things music/sound-related. After much research and contemplation, I decided to recreate one of the most important tools in my line of work, a midi controller. I use my MIDI controller for all of my musical creations because it is not only convenient but works incredibly well with my DAWs (digital audio workstations). The primary instrument that I use in many of my pieces is the synthesizer. This instrument inspires so many of my songs and allows me to manipulate sound in ways I could have never imagined. 

For this project, I will be taking inspiration from this tutorial ( https://www.youtube.com/watch?v=cHiTPoNCv1w ) and recreating my own controller. I hope to have quite a few buttons that will mimic a synthesizer and also add some sound effects for percussion (like a drum kit). I have yet to figure out how I want to implement p5 in all of this but I am thinking of trying to create a sound visualization in p5 that will maybe move whenever a button in Arduino is pressed. 

 

Here is the sample code for the Arduino portion of my project.

#include <Control_Surface.h> // Include the Control Surface library

// Instantiate a MIDI over USB interface.
USBMIDI_Interface midi;

// Instantiate a NoteButton object
NoteButton button {
  5,                             // Push button on pin 5
  {MIDI_Notes::C(4), Channel_1}, // Note C4 on MIDI channel 1
};

void setup() {
  Control_Surface.begin(); // Initialize Control Surface
}

void loop() {
  Control_Surface.loop(); // Update the Control Surface
}

These are the two sound libraries that I needed to download for this code to make a bit more sense.

https://github.com/arduino-libraries/MIDIUSB

https://tttapa.github.io/Control-Surface-doc/Doxygen/index.html

I attempted to draw the basic circuit 😔

Week 11 : Assignment (Mudi & Mariam)

 

Exercise 1

In this exercise, a potentiometer connected to an Arduino has been employed to influence the horizontal movement of an ellipse in p5.js. As you turn the potentiometer, the ellipse smoothly moves from side to side.

Exercise 2 :

Concept: Controlling the brightness of an LED using a slide bar in p5js

The left side of the slide bar (owl) will dim the brightness of the LED and the right side of the slide bar (sun) will make the LED brighter. We used the PWM pin 5 for the LED
a 10 K ohm resistor and two jumper wires to make the connection

code :

let brightness = 0; 
let slider;
let img;

//preload images to make sure everything is loaded before initializing the rest of the code
function preload(){
  img= loadImage('sun.png');
  img2 = loadImage('owl.png');
}
function setup() {
  createCanvas(400, 400);
  //create slider
  slider = createSlider(0, 255, 100);
  slider.position(width/2-50,height/2+130);
  slider.style('width', '80px');
}
function draw() {
  background('black');
  image(img,235,130,130,180); 
  image(img2,10,140,160,160);
  
  let val = slider.value();
  brightness = val;
  
  // instructions
  textAlign(CENTER,CENTER);
  textSize(12);
  fill(255)
  textStyle(BOLD)
  text("Controling the brightness of the LED using the slider ",width/2,100);
  
  //connects the serial port
  if (!serialActive) { 
    textSize(10);
    text("Press Space Bar to select Serial Port", 100, 30);
  } else {
    textSize(10);
    text("Connected",100,30);
  }
   
  

 

 

Week 11 Exercises

 

(Mudi & Mariam)

Exercise 1

In this exercise, a potentiometer connected to an Arduino has been employed to influence the horizontal movement of an ellipse in p5.js. As you turn the potentiometer, the ellipse smoothly moves from side to side.

Exercise 2 :

Controlling the brightness of an LED using a slide bar in p5js
Concept:

The left side of the slide bar (owl) will dim the brightness of the LED and the right side of the slide bar (sun) will make the LED brighter. We used the PWM pin 5 for the LED
a 10 K ohm resistor and two jumper wires to make the connection

 

Arduino Code:

int redled = 5; //PWM PIN
void setup() {
  pinMode(redled, OUTPUT);
  Serial.begin(9600);
  
  
  // initializing handshake
  while (Serial.available() <= 0) {
    Serial.println("a moment");  
    delay(200);               // wait 1/2 second
  }
}
void loop() {
  // wait for data to load from p5 before continuing code
  while (Serial.available()) {
    int brightness = Serial.parseInt(); 
    if (Serial.read() == '\n') {
      analogWrite(redled, brightness); // turn on LED and adjusts brightness
      Serial.println("ON"); 
    }
  }
}

 

Final Project Draft 1: Dodge it!

Concept:

For my final project, I pursued my initial idea and created a game that utilizes the ultrasonic sensor. The ultrasonic sensor will measure the distance from my hand and project that distance onto a ball’s horizontal position in p5. The ball can move left and right according to our hand movement. Multiple red rectangles are falling from above, and our job is to dodge them using our hands. There are also blue rectangles that spawn less frequently compared to the red ones. There is also a scoring system in which the score decreases by one after every frame, and hitting the red rectangles decreases the score by 2. Grabbing the blue rectangles that spawn less frequently is the only way to get a higher score. So the game becomes a fight against time and obstacles. As the score changes, the speaker that is connected to the breadboard also produces a different tone. Each score has its own unique tone produced by the speaker to make the game more engaging and fun. Therefore, this is a 2-way communication game, from p5 to Arduino and Arduino to p5.

Arduino:

Arduino will basically send the distance measured using the ultrasonic sensor to p5.Js. The Arduino side of the code will receive a score value from the p5. Arduino will input the echo pin(from ultrasonic sensor reading)  and outputs both the trig pin(from ultrasonic) and speaker pin(value received from p5).

Here is my code for it so far:

const int trigPin = 11;
const int echoPin = 12;
const int speakerPin = 9;

void setup() {
  // Start serial communication so we can send data
  // over the USB connection to our p5js sketch
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);

  // Outputs on these pins
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(speakerPin, OUTPUT);

  //start the handshake
  while (Serial.available() <= 0) {
    digitalWrite(LED_BUILTIN, HIGH); // on/blink while waiting for serial data
    Serial.println("0,0"); // send a starting message
    delay(300);            // wait 1/3 second
    digitalWrite(LED_BUILTIN, LOW);
    delay(50);
  }
}

void loop() {
  // sends a short pulse of ultrasonic sensor and waits a bit then receives it 
  digitalWrite(trigPin, LOW); 
  delayMicroseconds(2); 
  digitalWrite(trigPin, HIGH); 
  delayMicroseconds(10); 
  digitalWrite(trigPin, LOW); 

  // Time it takes for the pulse to travel back from the object long 
  int duration = pulseIn(echoPin, HIGH); 
  // Universal conversion of time into distance in cm 
  int distance = duration * 0.034 / 2;

  //SENDS TO P5
  Serial.println(distance);
  delay(50);

  //GETS FROM P5
  int score = Serial.parseInt();
  // Map the score to a frequency for the speaker
  int frequency = map(score, 0, 100, 100, 4000);
  // Play the tone
  tone(speakerPin, frequency);
}

The Arduino board:

p5:

For the p5 side of the code, the p5 will receive the distance value measured from Arduino and map it onto the canvas. The p5 will also send a live score value to Arduino. There are multiple classes to my p5 code: ball class, Obstacle class, TimeRectangle class, a class for the port connection, and finally the main sketch.

This is my attached main sketch class:

//Initialize all variables
let knobValue = 0;
let targetKnobValue = 0;
let easing = 0.08; // Adjust this value for the desired level of smoothing
let score = 0;
let lastFrameCount;

//initialize the class objets
let obstacles = [];
let timeRectangles = [];
let ball;


function setup()
{
  createCanvas(400, 300);
  //call the ball object
  ball = new Ball(width / 2, height - 30, 20);
  //line of code to set lastframe to the new one
  lastFrameCount = frameCount;
}

function draw() {
  //set background
  background(220);

  //if function to connect port 
  if (!serialActive)
  {
    fill(0);
    textSize(18);
    text("Press Space Bar to select Serial Port", 20, 30);
  } 
  //else function if the port is connected
  else 
  {
    // lerp function linear interpolates(smoothes the value we get from arduino using distance sensor)
    knobValue = lerp(knobValue, targetKnobValue, easing);
    //updates ball position according to distance sens
    ball.update(knobValue);

    // Draw ball
    ball.show();

    // Draw and move obstacles
    for (let i = obstacles.length - 1; i >= 0; i--) {
      obstacles[i].update();
      obstacles[i].show();

      // Remove obstacles that are off-screen
      if (obstacles[i].offscreen()) {
        obstacles.splice(i, 1);
      } else {
        // Check for collision with the ball
        if (obstacles[i].collision(ball)) {
          // Handle collision (e.g., decrease score)
          score= score-2;
          obstacles.splice(i, 1); // Remove the obstacle
        }
      }
    }

    // Draw and move timeRectangles(blue ones)
    for (let i = timeRectangles.length - 1; i >= 0; i--) {
      timeRectangles[i].update();
      timeRectangles[i].show();

      // Remove timeRectangles that are off-screen
      if (timeRectangles[i].offscreen()) {
        timeRectangles.splice(i, 1);
      } else {
        // Check for collision with the ball
        if (timeRectangles[i].collision(ball)) {
          // Handle collision (e.g., increase score)
          score += 5;
          timeRectangles.splice(i, 1); // Remove the timeRectangle
        }
      }
    }

    // Print the current knobValue
    fill(0);
    textSize(18);
    text('Knob Value: ' + str(knobValue), 20, 30);

    // Display score
    text("Score: " + score, 20, 60);

    // Spawn new obstacles and timeRectangles randomly
    if (random() < 0.01) {
      obstacles.push(new Obstacle());
    }
    if (random() < 0.005) {
      timeRectangles.push(new TimeRectangle());
    }
    
       // Update the score every second by subtracting current frame with last frame recorded in setup
    if (frameCount - lastFrameCount >= 60) {
      score = max(0, score - 1);
      lastFrameCount = frameCount;
    }
    
  }
}

function keyPressed() {
  if (key == " ") {
    // important to have in order to start the serial connection!!
    setUpSerial();
  }
}

function readSerial(data) {
  ////////////////////////////////////
  // READ FROM ARDUINO HERE
  ////////////////////////////////////

  if (data != null) {
    // Parse the data received from Arduino
    let fromArduino = split(trim(data), ",");
    targetKnobValue = int(fromArduino[0]);
    print(targetKnobValue);
  }

  //////////////////////////////////
  // SEND TO ARDUINO HERE
  //////////////////////////////////
  let sendToArduino= score + "\n";
   writeSerial(sendToArduino);
}

The P5 interface:

Future improvements:

As of now, I just put down the main codes and functions for both platforms. I will have to work more on the visuals, designs, and aethstics side as a whole of the p5 game.

 

Alien Intelligence w/Professor Leach

Attending professor’s Leach conference about his opinion about AI is certainly an interesting experience. He mostly spoke about how AI is this extremely smart web that connects all human minds and thoughts into one place, making it smarter than 5 people combined. Professor Leach praises the concept that AI is an extremely helpful tool that is open to all. 

My thoughts were mostly concerned with ethics. Should we as a community come up with regulations and a set of requirements to not make others use AI for their advantage. As an artist who mostly uses digital art (tablet and pen) I think people need to realize how harmful it is to use AI tools without proper manners. In the end AI is made from people’s thoughts and work, if people get used to “creating” art whether it be a drawn piece or a song I personally would consider it theft. Because it uses copies of other artists to replicate what a person wants. It might be fine to have it for personal use, however publicly claiming their own hard work is a little shameful. 

I really think regulations should be set for AI, and people should be mindful of the type of work they do.

WEEK 11 EXERCISES W/PIERRE

Exercise 1

IMG_7102

let rVal = 0;
let potentiometerInput = 0;
let circleX;


function setup() {
  createCanvas(640, 480);
  textSize(18);
  circleX = width/2;
}

function draw() {
  // one value from Arduino controls the background's red color
  background(255);

  // the other value controls the text's transparency value

  if (!serialActive) {
    text("Press Space Bar to select Serial Port", 20, 30);
  } else {
    text("Connected", 20, 30);
    

    // Print the current values
    text('potentiometerInput = ' + str(potentiometerInput), 20, 70);

  }
  
  //Draws the circle 
  circle(circleX,height/2,100);
}

function keyPressed() {
  if (key == " ") {
    // important to have in order to start the serial connection!!
    setUpSerial();
  }
}

// This function will be called by the web-serial library
// with each new line of data. The serial library reads
// the data until the newline and then gives it to us through
// this callback function
function readSerial(data) {
  ////////////////////////////////////
  //READ FROM ARDUINO HERE
  ////////////////////////////////////

  if (data != null) {
    // make sure there is actually a message
    // split the message
    let fromArduino = split(trim(data), ",");

    // if the right length, then proceed
    if (fromArduino.length == 1) {
      // only store values here
      // do everything with those values in the main draw loop
      
      // We take the string we get from Arduino and explicitly
      // convert it to a number by using int()
      // e.g. "103" becomes 103
      
      
      potentiometerInput = int(fromArduino[0]);
      
      //Maps the potentiometer input value to the width of the canvas.
      circleX = map(potentiometerInput,0,1023,0,width);


      
    }
    let sendToArduino = "\n";
    writeSerial(sendToArduino);
    
  }
}

P5 ⬆️

void setup() {

  Serial.begin(9600);

  // start the handshake
  while (Serial.available() <= 0) {
    digitalWrite(LED_BUILTIN, HIGH); // on/blink while waiting for serial data
    Serial.println("0,0"); // send a starting message
    delay(300);            // wait 1/3 second
    digitalWrite(LED_BUILTIN, LOW);
    delay(50);
  }
}

void loop() {
  // wait for data from p5 before doing something
  while (Serial.available()) {
    digitalWrite(LED_BUILTIN, HIGH); // led on while receiving data
      
      delay(5);
       if (Serial.read() == '\n') {
      int potentiometer = analogRead(A1);
      delay(5);
      Serial.println(potentiometer);
      Serial.print(',');
      Serial.println(potentiometer);
       }
    }
      digitalWrite(LED_BUILTIN, LOW);
  }

Arduino ⬆️

Exercise 2

 ASSIGNMENT 2

while (Serial.available()) {
    Serial.println("0,0");
    digitalWrite(LED_BUILTIN, HIGH); // led on while receiving data
    int value = Serial.parseInt();
    int value2 = Serial.parseInt();
    if (Serial.read() == '\n') {
      analogWrite(ledPin, value);
      analogWrite(ledPin2, value2);
    }
  }

Arduino ⬆️

function readSerial(data) {
  if (data != null) {
    //////////////////////////////////
  //SEND TO ARDUINO HERE (handshake)
  //////////////////////////////////
  value = int(map(mouseY,0, height, 0, 255));
  value2 = int(map(mouseX,0, width, 0, 255));
  let led1 = value + "\n";
  let led2 = value2 + "\n";
  writeSerial(led1);
  writeSerial(led22);
  print(value);
  print(value2)
    
    
  }

p5 ⬆️

ASSIGNMENT 3

void loop() {
  // wait for data from p5 before doing something
  while (Serial.available()) {
    // led on while receiving data
    digitalWrite(LED_BUILTIN, HIGH); 
    // gets value from p5
    int value = Serial.parseInt();
    // led switch from p5 value input
    if (Serial.read() == '\n') {
      if (value == 1) {
        digitalWrite(ledPin, HIGH);
      }
      else {
        digitalWrite(ledPin, LOW);
      }
      
      // gets sensor value
      int sensor = analogRead(A0);
      delay(5);
      // sends sensor value to p5
      Serial.println(sensor);
    }
  }
  digitalWrite(LED_BUILTIN, LOW);
  
}

Arduino ⬆️

 

W11 assignments

Assignments

Assignment 1:

P5 Code snippet:

function readSerial(data) {
  ////////////////////////////////////
  //READ FROM ARDUINO HERE
  ////////////////////////////////////

  if (data != null) {
    // make sure there is actually a message
    // split the message
    let fromArduino = split(trim(data), ",");

    // if the right length, then proceed
    if (fromArduino.length == 1) {
      // only store values here
      // do everything with those values in the main draw loop
      
      // We take the string we get from Arduino and explicitly
      // convert it to a number by using int()
      // e.g. "103" becomes 103
      
      
      potentiometerInput = int(fromArduino[0]);
      
      //Maps the potentiometer input value to the width of the canvas.
      circleX = map(potentiometerInput,0,1023,0,width);


      
    }
    let sendToArduino = "\n";
    writeSerial(sendToArduino);
    
  }
}

Arduino code snippet:

void setup() {

  Serial.begin(9600);

  // start the handshake
  while (Serial.available() <= 0) {
    digitalWrite(LED_BUILTIN, HIGH); // on/blink while waiting for serial data
    Serial.println("0,0"); // send a starting message
    delay(300);            // wait 1/3 second
    digitalWrite(LED_BUILTIN, LOW);
    delay(50);
  }
}

void loop() {
  // wait for data from p5 before doing something
  while (Serial.available()) {
    digitalWrite(LED_BUILTIN, HIGH); // led on while receiving data
      
      delay(5);
       if (Serial.read() == '\n') {
      int potentiometer = analogRead(A1);
      delay(5);
      Serial.println(potentiometer);
      Serial.print(',');
      Serial.println(potentiometer);
       }
    }
      digitalWrite(LED_BUILTIN, LOW);
  }

 

Assignment 2: Video2

Code snippet Arduino:

while (Serial.available()) {
    Serial.println("0,0");
    digitalWrite(LED_BUILTIN, HIGH); // led on while receiving data

    int value = Serial.parseInt();
    int value2 = Serial.parseInt();

    if (Serial.read() == '\n') {
      analogWrite(ledPin, value);
      analogWrite(ledPin2, value2);
    }
  }

p5 snippet:

function readSerial(data) {
  if (data != null) {
    //////////////////////////////////
  //SEND TO ARDUINO HERE (handshake)
  //////////////////////////////////
  value = int(map(mouseY,0, height, 0, 255));
  value2 = int(map(mouseX,0, width, 0, 255));
  let led1 = value + "\n";
  let led2 = value2 + "\n";
  writeSerial(led1);
  writeSerial(led22);
  print(value);
  print(value2)
    
    
  }

Assignment 3: video3

Arduino snippet:

void loop() {

  // wait for data from p5 before doing something
  while (Serial.available()) {

    // led on while receiving data
    digitalWrite(LED_BUILTIN, HIGH); 

    // gets value from p5
    int value = Serial.parseInt();

    // led switch from p5 value input
    if (Serial.read() == '\n') {
      if (value == 1) {
        digitalWrite(ledPin, HIGH);
      }
      else {
        digitalWrite(ledPin, LOW);
      }
      
      // gets sensor value
      int sensor = analogRead(A0);
      delay(5);

      // sends sensor value to p5
      Serial.println(sensor);
    }
  }

  digitalWrite(LED_BUILTIN, LOW);
  
}