🔍

„hihihide behind the clouds“ – the most minimalistic one poti game

This first minimal approach to interface alternative user interface elements, like potentiometers or sensors comes along with a proper oldschool Firmata/Arduino/Processing pipeline. Also check out the minimalistic custom firmata for flickerless LED action 😉 >>> https://turboflip.de/processing2arduino-firmata-basic-setup/

Assets needed:


import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
  
int led_pin = 10; // testLED on pin 10!
int analog_pin = 0;  // analog input from poti on A0
  
  
void setup() {
    
 // fullScreen();
  size(600,300); // setup the stage size
  background(22);
   
  // Prints out the available serial ports.
  println(Arduino.list());
   
  // initalize Arduino (  pick first COM device > need to be changed if u have more! )
  arduino = new Arduino(this, Arduino.list()[1], 57600);
   
  // set the LED pin to output mode
  arduino.pinMode(led_pin,Arduino.PWM);
      
  print(" >>> --- Arduino says Hello ;) -- >>> ");
  println(arduino);
 
    gamesetup();
   
  }
  
  
void draw() {
  
     gameloop();
    
}


// ------------------------------------------------------
// ---------------------------------------------------------


PImage myimg; // global variable of my loaded images
PImage mycloudimg;

float paddlex = 200; // position of my paddle

float accx = 3;
float accy = 3;

// current ball position
float posx = 200;
float posy = 200;

void gamesetup(){
  
  // load the image
   myimg = loadImage("emoj.png");
   mycloudimg = loadImage("fluffy_cloud1.png"  );
   
  // set a random acceleration 
  accx = random(1,3);
  accy = random(1,3);
  
  println(" game setup done ");
}

void gameloop(){
  
  // add acceleration to my position
   posx += accx;
   posy += accy; 
   // reflection behaviour
   if( posx > width -80  ||  posx < 0 ){
      accx *= -1.03;
      accx += random( -.4,.4 );  
  }
  if( posy > height-80  ||  posy < 0 ){
      accy *= -1.03;
      accy += random( -.4,.4 );
  }
  // get the poti value here and savbe it in paddlex
     int potiIn = arduino.analogRead(analog_pin); // read poti value > outputs 0 - 1024
     
     // map the input value from 0-1024 to 0-400
     paddlex = map(potiIn, 0, 1024, 0 , width);
     
     float absx =  abs(paddlex - posx);

     if(absx<80){
        arduino.analogWrite(led_pin, 0);
        background(22);
     }else{
       arduino.analogWrite(led_pin, 255);
       background(222);
     }
     
  
    // draw the sun ---------
   image( myimg,posx,posy, 80, 80  );

    // draw a stack of clouds
    for(int i=0;i<9;i++){
       
      float xoff = sin( millis()*.004 + i*.5 + paddlex*0.05 )*20;
       image(mycloudimg, paddlex + xoff,i*40-40, 140,90);
   
   }

}