WK 10- Meera :

For this week’s assignment I went with a simple paddle with ball game. the aim is to get the paddle and the bored to touch, their is a count for any times the played either missed or hit the paddle with the ball. The count can be reloaded just by pressing the mouse. The paddle can be moved using the potentiometer.  It was very simple to make, however, I did face some difficulty understanding how to connect the Arduino to the processing. eventually after research and watching our class video a couple times , I was able to get it to work.

this is the Arduino code :

void setup() {
pinMode(0,INPUT);
Serial.begin (9600);
  

}

void loop() {
  int reading = analogRead (0);
  Serial.println ( reading );
  delay (50);
  
}

This is the processing code :

import processing.serial.*;

float ballX = 200;
float ballY =100;
float speedX= 7;
float speedY= 0;
int hit  = 0;
int miss =0;
String serialPortName ="/dev/cu.usbmodem141101";
Serial arduino;
float batPosition;
PImage bat;
void setup () {

  size ( 600, 600);
   bat = loadImage("bat.png");
 if(serialPortName.equals("/dev/cu.usbmodem141101")) scanForArduino();
  else arduino = new Serial(this, serialPortName, 9600);


}


void draw() {
  
  if (mousePressed){ 
    hit =0; miss =0;
  }
  if((arduino != null) && (arduino.available()>0)) {
    String message = arduino.readStringUntil('\n');
    if(message != null) {
      int value = int(message.trim());
      batPosition = map(value,0,1024,0,width);
    }
  }

  float paddle =100 ; // can make the paddle get smaller is if i add 1000/ (hit+10) 
  if (ballX <0 || ballX > width ) speedX = -speedX;
  if ( ballY> height) {
    speedY = -speedY;
float distance = abs(mouseX - ballX);
if (distance < paddle ) hit += 1;
else  miss +=1;
}else speedY +=1;

  ballX +=speedX;
  ballY +=speedY;

  background(0, 0, 0);
  ellipse ( ballX, ballY, 50, 50);
   image(bat,batPosition,height-bat.height); //rect (width-paddle, height -10, 2*paddle, 10); // where i want to connect the potntiometer cause it is the paddle
text ( " hit :" + hit ,10,30);
text ( " miss :" + miss ,90,30);
}
void stop()
{
  arduino.stop();
}


void scanForArduino()
{
  try {
    for(int i=0; i<Serial.list().length ;i++) {
      if(Serial.list()[i].contains("tty.usb")) {
        arduino = new Serial(this, Serial.list()[i], 9600);
      }
    }
  } catch(Exception e) {
    // println("Cannot connect to Arduino !");
  }
}

This is the final demo of the game :

Link for the Game: 

 

this was where I got the code to connect them together: https://www.instructables.com/Getting-started-with-Arduino-Potentiometer-Pong/

 

 

 

 

For the final project idea :

 

I have many ideas, but one that can work  was actually  inspired from an idea that Sarah had a while a go.

Sarah talked one time about a children’s game and i had the idea from that.

 

The concept would involve, buttons and a potentiometer.

The game would be a learning game for kids, the buttons would represent colors and the potentiometer and be used to draw things like circles and squares.

So far this idea , to me, is a foundational concept I wanna try. What I have pitched is not the whole concept, the further I explore I will be able to see what I can or can’t do and also mainly what I should and shouldn’t do. I believe it’ll be difficult but I do wanna explore this idea and I hope It works out.

During the break room meeting, I pitched this idea to my classmates who were there with me. Nathan gave me such a helpful idea , he said I could try having only two buttons and the my processing could be a type of quiz. I really liked this idea, it could be very simple for kids to learn from and after some research I believe it is doable .  There for  finally , for my final project I will be creating a simple trivia game for children using processing and with Arduino I will be using two button for the player to pick from the two option I will provide them with.

One thought on “WK 10- Meera :”

  1. Meera, this code is different than the examples we went over in class. It’s ok to use code you find somewhere else, but you need to say where you got that from in your blog post and give credit, otherwise, it is plagiarism.

Leave a Reply