Project in progress
Potentiometer Game

Potentiometer Game

I used a potentiometer to control a game's avatar.

  • 1,577 views
  • 0 comments
  • 6 respects

Components and supplies

Apps and online services

About this project

I made this game because I need to learn to connect the Arduino and Processing program. I had a lot of fun and learned a lot of things. You need this picture to do this project.

Code

proccesingJava
It is arkanoid game.
import processing.serial.*;
Serial port;
float brightness=0;

float circleX;
float speedX = 5;
float circleY;
float speedY = 3;
float rectX= 0;
float rectY= 0;
float rect0= rectX + 70;
float rect1 = rectY + 30;
float rectp= 70;
float rectv= 30;
float rect2= rectX + 140;
float rect3 = rectY + 60;
float recto= 140;
float rectm= 0;
float rect4= rectX + 210;
float rect5 = rectY + 30;
float rectl= 210;
float rectr= 30;
float rect6= rectX + 280;
float rect7 = rectY + 60;
float rectq= 280;
float rectw= 0;
float rect8= rectX + 350;
float rect9 = rectY + 30;
float rectj= 350;
float rectk= 30;
float rect10= rectX + 420;
float rect11 = rectY + 60;
float rectt= 100;
float rrect = 20;
float mmclick;
float torta;

PImage img;

void setup () {
  
  port= new Serial(this  , "COM12",9600);
port.bufferUntil('\n');
  
  size(640,360);
  
  circleX = random(540);
  circleY = 160;
  
  img = loadImage("ark.jpg");
  
}

 void mousePressed(){
circleX=random(640);
circleY=50;


}

void draw() {

  background(0,30,30); 
  
    image(img,10,5);
  
  stroke(50);
  fill(255);
  ellipse(circleX,circleY,24,24);
  
  fill(0,0,255);
  rect(rectj,rectk,70,30,3,3,3,3);
  
  fill(255,0,0);
  rect(recto,rectm,70,30,3,3,3,3);
  
  fill(255,0,0);
  rect(rectq,rectw,70,30,3,3,3,3);
  
  fill(0,0,255);
  rect(rectl,rectr,70,30,3,3,3,3);
  
  fill(255,0,0);
  rect(rectX,rectY,70,30,3,3,3,3);
  
  fill(0,0,255);
  rect(rectp,rectv,70,30,3,3,3,3);
  
  fill(200);
  rect(brightness,340,rectt,rrect,18,18,18,18);

  circleX = circleX + speedX;
  circleY = circleY + speedY;
   if (circleX > width) {
    speedX = -5; 
  }
  
   if (circleX < 0) {
    speedX = 5; 
  }
   
   if (circleY < 0) {   
    speedY = 3; 
  }
  
   if ((circleX > brightness)&&(circleY > 340 )&&(circleX<mmclick)){
    speedY = -3;
  }
  
   if (circleY > 350 ){
    speedY = 3;
  }

 if ((circleX >= rectX)&&(circleX <= rect0)&&(circleY>=rectY)&&(circleY<=rect1)) {
rectX = -500;
rectY = -500;
rect0 = -500;
rect1 = -500;
speedX = 5;
speedY = 3;
 } 
  
   if ((circleX >= rectp)&&(circleX <= rect2)&&(circleY>=rectv)&&(circleY<=rect3)) {
rectp = -500;
rectv = -500;
rect2 = -500;
rect3 = -500;
speedX = 5;
speedY = 3;
 } 
 
    if ((circleX >= recto)&&(circleX <= rect4)&&(circleY>=rectm)&&(circleY<=rect5)) {
recto = -500;
rectm = -500;
rect4 = -500;
rect5 = -500;
speedX = -5;
speedY = 3;
 } 
     if ((circleX >= rectl)&&(circleX <= rect6)&&(circleY>=rectr)&&(circleY<=rect7)) {
rectl = -500;
rectr = -500;
rect6 = -500;
rect7 = -500;
speedX = -5;
speedY = 3;
 } 
 
      if ((circleX >= rectq)&&(circleX <= rect8)&&(circleY>=rectw)&&(circleY<=rect9)) {
rectq = -500;
rectw = -500;
rect8 = -500;
rect9 = -500;
speedX = 5;
speedY = 3;

 }  
       if ((circleX >= rectj)&&(circleX <= rect10)&&(circleY>=rectk)&&(circleY<=rect11)) {
rectj = -500;
rectk = -500;
rect10 = -500;
rect11 = -500;
speedX = 5;
speedY = 3;
 } 
 
          if ((rectX == -500)&&(rectY == -500)&&(rect1 == -500)&&(rect0 == -500)&&(rectp == -500)&&(rectv == -500)&&(rect2 == -500)&&(rect3 == -500)
       &&(recto == -500)&&(rectm == -500)&&(rect4 == -500)&&(rect5 == -500)&&(rectl == -500)&&(rectr == -500)&&(rect6 == -500)&&(rect7 == -500)
       &&(rectq == -500)&&(rectw == -500)&&(rect8 == -500)&&(rect9 == -500)&&(rectj == -500)&&(rectk == -500)&&(rect10 == -500)&&(rect11 == -500)) {
circleX = 300;
circleY = 200;
rectX = random(640);
rectY = 0;
rect0 = rectX + 70;
rect1 = rectY + 30;
rectp = random(640);
rectv = 30;
rect2 = rectp + 70;
rect3 = rectv + 30;
recto = random(640);
rectm = 60;
rect4 = recto + 70;
rect5 = rectm + 30;
rectl = random(640);
rectr = 90;
rect6 = rectl + 70;
rect7 = rectr + 30;
rectq = random(640);
rectw = 120;
rect8 = rectq + 70;
rect9 = rectw + 30;
rectj = random(640);
rectk = 150;
rect10 = rectj + 70;
rect11 = rectk + 30;
rectt = rectt - 20;
mmclick = mmclick - 20;

   }

 if ((rectX == -500)&&(rectY == -500)&&(rect1 == -500)&&(rect0 == -500)) {
   textSize(25);
   text("100",35,310);
   
 }
  if ((rectp == -500)&&(rectv == -500)&&(rect2 == -500)&&(rect3 == -500)) {
   textSize(25);
   text("100",35,310);
   
 }
   if ((recto == -500)&&(rectm == -500)&&(rect4 == -500)&&(rect5 == -500)) {
   textSize(25);
   text("100",35,310);
   
 }
    if ((rectl == -500)&&(rectr == -500)&&(rect6 == -500)&&(rect7 == -500)) {
   textSize(25);
   text("100",35,310);
   
 }
    if ((rectq == -500)&&(rectw == -500)&&(rect8 == -500)&&(rect9 == -500)) {
   textSize(25);
   text("100",35,310);
   
 }
     if ((rectj == -500)&&(rectk == -500)&&(rect10 == -500)&&(rect11 == -500)) {
   textSize(25);
   text("100",35,310);
   
 }
 
 if ((rectp == -500)&&(rectv == -500)&&(rect2 == -500)&&(rect3 == -500)&&(rectX == -500)&&(rectY == -500)&&(rect1 == -500)&&(rect0 == -500)) {
   text("100",500,500);
   textSize(25);
   text("200",35,310);
   
 }
  if ((rectX == -500)&&(rectY == -500)&&(rect1 == -500)&&(rect0 == -500) && (recto == -500)&&(rectm == -500)&&(rect4 == -500)&&(rect5 == -500)) {
   text("100",500,500);
   textSize(25);
   text("200",35,310);
   
 }
  if ((rectX == -500)&&(rectY == -500)&&(rect1 == -500)&&(rect0 == -500) &&(rectl == -500)&&(rectr == -500)&&(rect6 == -500)&&(rect7 == -500)) {
   text("100",500,500);
   textSize(25);
   text("200",35,310);
   
 }
   if ((rectX == -500)&&(rectY == -500)&&(rect1 == -500)&&(rect0 == -500) &&(rectq == -500)&&(rectw == -500)&&(rect8 == -500)&&(rect9 == -500)) {
   text("100",500,500);
   textSize(25);
   text("200",35,310);
   
 }
    if ((rectX == -500)&&(rectY == -500)&&(rect1 == -500)&&(rect0 == -500) &&(rectj == -500)&&(rectk == -500)&&(rect10 == -500)&&(rect11 == -500)) {
   text("100",500,500);
   textSize(25);
   text("200",35,310);
   
 }
     if ((rectp == -500)&&(rectv == -500)&&(rect2 == -500)&&(rect3 == -500) &&(rectj == -500)&&(rectk == -500)&&(rect10 == -500)&&(rect11 == -500)) {
   text("100",500,500);
   textSize(25);
   text("200",35,310);
   
 }
      if ((rectp == -500)&&(rectv == -500)&&(rect2 == -500)&&(rect3 == -500) &&(rectq == -500)&&(rectw == -500)&&(rect8 == -500)&&(rect9 == -500)) {
   text("100",500,500);
   textSize(25);
   text("200",35,310);
   
 }
       if ((rectp == -500)&&(rectv == -500)&&(rect2 == -500)&&(rect3 == -500) &&(rectl == -500)&&(rectr == -500)&&(rect6 == -500)&&(rect7 == -500)) {
   text("100",500,500);
   textSize(25);
   text("200",35,310);
   
 }
        if ((rectp == -500)&&(rectv == -500)&&(rect2 == -500)&&(rect3 == -500) &&(recto == -500)&&(rectm == -500)&&(rect4 == -500)&&(rect5 == -500)) {
   text("100",500,500);
   textSize(25);
   text("200",35,310);
   
 }

  mmclick = brightness+100;
} 

void serialEvent (Serial port)
 {
   brightness= float(port.readStringUntil('\n'));
 }
arduino codeArduino
int potPin = 0;


void setup() {
  Serial.begin(9600);

}

void loop() {
 int val = map (analogRead(potPin),0,1023,0,590); 
Serial.println(val);
delay(50);
}

Schematics

potentiometer_GOfjc4usXe.png
Potentiometer gofjc4usxe

Comments

Similar projects you might like

Arduino Pocket Game Console + A-Maze - Maze Game

Project tutorial by Alojz Jakob

  • 5,316 views
  • 7 comments
  • 18 respects

Arduino Game By LCD

Project tutorial by Mohammed Magdy

  • 32,861 views
  • 31 comments
  • 108 respects

Using iShield Gauge with potentiometer

Project tutorial by Victor Carreño

  • 1,782 views
  • 3 comments
  • 7 respects

Touch display: Game "Flappy Bird"

by MakerRobotics

  • 8,869 views
  • 15 comments
  • 56 respects

Create a Game with Arduino and Processing

Project showcase by Nicholas_N

  • 5,083 views
  • 3 comments
  • 5 respects

Arduino LED Matrix Game of Life

Project showcase by aerodynamics

  • 2,391 views
  • 0 comments
  • 15 respects
Add projectSign up / Login