Assignment 15
Interface and application programming

all source codes available here

in this assignment i'm going to interface my input devices assignment with my laptop

my first interface program was written in python do display the LDR results on the laptop which is available here

here's the result video :


the application

i wrote a simple processing application which acts like a simple game, it moves a small ball upon the LDR reading received over the Serial port, source code available here

or here:

import processing.serial.*;

Serial port;

int x = 0;
int speed = 2;
int i;
float num;
void setup(){
  size (200, 200);
  smooth();
  println(Serial.list());
  String portName = Serial.list()[0];
  port = new Serial(this, "/dev/ttyUSB1", 9600);
  port.write(65);
}
void draw (){
  delay(100);
  background(255);
  while(port.available() > 0){
   String input =  port.readStringUntil('\n');
// i= Integer.parseInt(
     if (input == null)
        {
        }
   else if(input != null) {
      println(input);
       // int i = int(input);
     num=float(input);
     print("i");
     println(i);
     
    }
   int z = int(num);
  x = z/4;
  if ((x > width ) || (x<0)){
    speed = speed * -1;
  }
//  println(x);
  stroke(0,0,255);
  fill(255,0,0);
  ellipse(x,100,32,32);
}
}


here's the result videos: