Final Project Documentation

Game idea:
The Asteroids game is a classic arcade game that has been enjoyed by many people over the years. In this version of the game, you control a spaceship and must navigate through a field of asteroids, shooting them to destroy them and avoid being hit. The game is challenging and exciting, and the addition of the Arduino joystick adds a new level of interactivity. Working with p5js and Arduino was both fun and challenging. Combining these two technologies allowed me to create a dynamic game that could be controlled with a joystick.

Box:
Making the box for the joystick was a fun and challenging project. The first step was to gather the materials that I would need, which included wood, screws, and a joystick. I was fortunate to have a professor who was able to cut the pieces of wood to the right size, which saved me a lot of time and effort. Once the pieces were cut, I began the process of assembling the box. This involved screwing the pieces together and attaching the joystick. The process of attaching the joystick was complicated and took a lot of time, but it was rewarding to see the final product coming together. After the box was assembled, I decided to give it a coat of spray paint to make it look more polished and finished. This added an extra layer of protection to the wood and gave the box a more professional look. In the end, I was very happy with the way the box turned out. It was sturdy and well-constructed, and the addition of the joystick made it a perfect fit for my Asteroids game.

Implementation (p5js and Arduino):
Arduino code:

void setup()  
{
  Serial.begin(9600);
  pinMode(2, INPUT);
  digitalWrite(2,HIGH); 
  pinMode(A0, INPUT);
}

void loop() 
{
  int potVal = analogRead(A0);
  int buttonVal = digitalRead(2);
  Serial.print(buttonVal);
  Serial.print(",");
  Serial.print( potVal);
  Serial.println();
}


red – 5V
green – A0 (x-axis values)
yellow – A1 (y-axis values not used)
blue – 2 (button values)
black – GRW

p5js code:
These are the function used to connect the Arduino values with the game. The rest of the code is the one from my midterm project.

function makePortButton() 
{  
  portButton = createButton("choose port");
  portButton.position(10, 10);
  portButton.mousePressed(choosePort);
}

function choosePort() 
{
  if (portButton) portButton.show();
  serial.requestPort();
}
 

function openPort() 
{
  serial.open().then(initiateSerial);
 
  function initiateSerial() 
  {
    console.log("port open");
  }
  
  if (portButton) portButton.hide();
}
 
function portError(err) {
  alert("Serial port error: " + err);
}

function serialEvent() {
  
  let data = serial.readStringUntil('\n');

  try
  {
    values = split(data, ',');      
  }
  catch(err)
  {
    //print("NAN");
  }
  
}

function portConnect() {
  console.log("port connected");
  serial.getPorts();
}

function portDisconnect() {
  serial.close();
  console.log("port disconnected");
}
 
function closePort() {
  serial.close();
}


function controls2(x,y){

  if(!isNaN(y) && y!=2 && y > 0)
  {
     gamestatus = "running";
  }
  if (!isNaN(y) && y!=2 && y > 0)
  {
    makebullet(shooter.x,shooter.y);    
  }
  
}


function controls(x,y){
  
  if(!isNaN(y) && y!=2 && y > 0)
  {
     gamestatus = "running";
  }
  
    
  if(!isNaN(y) && y!=2 && fired == 0)
  {
    if(y>0)
     {
       makebullet(shooter.x,shooter.y);
       fired = 1;
     }
  }
  
  if(!isNaN(y) && y!=2 && fired != 0 && y == 0)
  {
    fired = 0;
  }
  if(x<340 && x>250)
  {
    rate = -2;
  }
  else if(x<250)
  {
    rate = -5;
  }
  else if(x>340 && x<680)
  {
    rate =0;
  }
  else if(x>680 && x<850)
  {
    rate = 2;
  }
  else if(x>850 && x<950)
  {
    rate = 5;
  }
  else
  {
    
  }
}

User experience:

Reflections and improvements:
Figuring out how to use p5js and Arduino together was not easy, but it was a rewarding experience. I learned a lot about programming and electronics as I worked on the project, and I was able to create a unique and engaging game. I am proud of the work that I put into the game, and I hope that others will enjoy playing it as much as I enjoyed making it. Overall, I am pleased with the final product of my Asteroids game. It is a fun and exciting game that is sure to provide hours of entertainment. The addition of the Arduino joystick makes it even more engaging, and I am glad that I was able to incorporate this technology into the game. I hope that others will enjoy playing it as much as I enjoyed creating it.

Musical instrument

Concept:

For this week’s assignment, we were struggling to come up with an idea so we scouted the internet for inspiration. We came across this video https://www.youtube.com/watch?v=J8XNTHETgxU and thought it was a perfect and cool idea! The concept is essentially playing notes by moving your hands at a certain distance away from the ultrasonic sensor. The notes we used were C,D,E,F,G,A,B. The materials we needed were one breadboard, 9 wires, one ultrasonic sensor, one switch, one 10ohms resistor, and one piezo buzzer. We also placed down pieces of paper with the notes on it to help us navigate the keys.

This is an attempt at drawing the schematic:

This is what the breadboard looked like:

This is the final outcome where we played mary had a little lamb:

This is the code we are most proud of:
// plays note at a certain distance

if (distance < 0 || distance > 50 || buttonState == LOW) { //if not presed and not in front

noTone(9); //dont play music

}

else if (( buttonState == HIGH)) { //if pressed

int sound = map(distance, 0, 50, 0, 6); //map distance to the array of notes
tone(9, notes[sound]); //call a note depending on distance

}

Reflections and improvements:
Not sure if the schematic is correct. When we would reach A or B the sound would sometimes become fuzzy or cut out so it would be nice if we could fix that. It would be better if we designed our own keyboard.

Analog input & output

Concept:

Analog input and output is a fundamental concept in electronics and microcontrollers, such as the Arduino. In this project, we will be using analog input and output to control a pair of LEDs, one red and one blue, which will mimic the flashing lights of a police car. This will be achieved by using a sensor, such as a motion sensor, to detect when a hand is waved in front of the LEDs. The reason for choosing this particular project is to gain a better understanding of analog input and output, as well as to create a fun and interactive project using the Arduino. By using a sensor to control the flashing of the LEDs, we can create a sense of realism and add an extra layer of interactivity to the project.

Reflections and improvements:

As someone who enjoys tinkering with gadgets and technology, working on an analog input and output project was a lot of fun for me. I was excited to see how the switch would work and how the output would be displayed on the screen. Unfortunately, the video of my project got corrupted and I was unable to show the switch in action (when pressed while the motion sensor was used the LED would flash).

Despite this setback, I was still happy with how the project turned out. The analog input and output functioned exactly as I had expected, and I was able to learn a lot about how these types of systems work. I enjoyed the process of building and testing the project, and it was satisfying to see it all come together in the end.

Looking back, there are a few things I would do differently if I had the chance to work on this project again. For one, I would make sure to back up the video of the project before showing it to others. This way, if something goes wrong with the video, I would still have a copy of it to refer to.

Unusual switch

Concept:

Making a switch with Arduino that lights up a LED when you step on it was an efficient and convenient solution for waking up in the morning. I chose to create this project because I wanted to make something that was easily accessible and user-friendly. The switch was designed to be placed next to the bed, so that when you wake up in the morning, all you have to do is step on it to turn on the LED and start your day.


Reflections and improvements:

Reflecting on the experience of making a switch with Arduino, I found it to be both a difficult and a fun process. Initially, it was challenging for me to come up with an idea for the project. I wanted to create something that was useful and interesting, but I struggled to come up with a specific concept. Eventually, I decided to make a switch that would light up a LED when you step on it, and I found this idea to be both simple and useful. Once I had settled on an idea for the project, the process of creating the switch was enjoyable and rewarding. I enjoyed learning about Arduino and how to use it to create a simple circuit. I also enjoyed writing the program to make the LED light up when the piezo sensor was triggered. This required me to learn some basic programming concepts, such as functions and conditional statements, and I found this to be a challenging but rewarding experience.

Midterm Project: Asteroids Game

Concept:

Asteroids is a classic video game that has captivated players for decades. As a child, I was drawn to the game’s simple yet challenging gameplay and the excitement of blasting asteroids into tiny pieces. When I heard that I had the option to choose my own midterm project, I immediately knew that I wanted to create my own version of the Asteroids game. One of the reasons I chose to create an Asteroids game is because it is a fun and engaging project. The game’s simple premise and mechanics make it easy to understand and play, but it also offers a challenge for players to master. I enjoy games that are easy to pick up but difficult to master, and Asteroids fits that description perfectly. Another reason I chose to create an Asteroids game is because it reminds me of my childhood. I have fond memories of playing Asteroids at the arcade with my friends, and I wanted to recreate that experience for myself and others. By creating my own version of the game, I can relive those memories and share them with others.

Reflections and improvements:

Creating an Asteroids game in p5.js was a challenging and rewarding experience. This required a lot of experimentation and trial and error, but I found the process to be enjoyable and educational. Challenge I faced was making the game visually appealing. In the original Asteroids game, the graphics were simple but effective, with clean lines and geometric shapes. I wanted to recreate this aesthetic in my game, so I spent a lot of time experimenting with different design choices to find the right look. I also had to figure out how to make the game run smoothly, so that the movement and shooting would feel responsive and satisfying to the player. In the end, I was able to create a functional and visually appealing version of the Asteroids game in p5.js. I was proud of the work I had done, and I received positive feedback from my peers and instructors. Overall, the experience of creating an Asteroids game in p5.js was challenging but rewarding, and I learned a lot about game development and programming in the process.

OOP project

Concept:

For object oriented programming my initial idea was to create a circle within a circle, something like this https://dribbble.com/shots/13450284-Creative-Coding-Tusi-Couple. I ran into some problems with the addition of line and dots when the mouse was clicked.

Reflections and improvements:

I would like to improve skills in interactivity between user and program, how to incorporate simple methods and have a successful outcome.

Art piece

Concept:

A single line, judiciously placed around the main features, might suggest several moods. With this artwork, I wanted to display a variety of colours and lines that, when combined, display a range of emotions. Horizontal lines frequently convey a sense of stability, peace, and tranquility when utilized in conjunction with other shapes. The word “horizontal” comes from the word “horizon,” which is another symbol for perspective, separation, and tranquility. The possibility for mobility is strongly shown by vertical lines. When constructing perspective drawings and scenarios, vertical lines are frequently utilized in conjunction with horizontal lines as lines of reference.

Reflections and improvements:

Making this was enjoyable and relatively easy. But I wish there had been some kind of interactive component. Something that might change colours dependent on mouse movement. After this design was finished, I tried adding more visuals, but I ran into some problems. That is something that I would want to include in this sketch.

Self-portrait

Concept:

My idea is based on my hometown, Ohrid, a beautiful small town in Macedonia. For most of the year its cold and rainy, but when it snows for me its the most magical time of the year.

Reflections and improvements:

I would like to focus on improving interactive features on my projects and learning new skills to incorporate in p5js.