Assignment 15 - week 15 - May 06

    Write an application that interfaces with an input &/or output device

    Interface and Application Programming

    This week assignment is about interface and application programming, so for this assignment I chose processing as programming language. Processing is not only a programming language, it's also a development enviroment wich can be downloaded here. Processing let's you build graphic user interfaces ranging from simple to complex, but most important is the support for custom libraries, for example there's been lot of support for kinnect, OpenCV, arduino, OSC. The interface I developed uses the serial communication for interfacing Ardunio UNO

    int alpha;
    int dir=1;
    
    void setup () {
      size (500, 500);
      background (#DAF2EC);
    }
    
    void draw () {
      background (#DAF2EC);
      fill (#F2AA22, alpha);
      stroke(#5F485D);
      ellipse(250, 250, 400, 400);
      alpha=alpha+1*dir;
      if (alpha>=255) {
        dir=-1;
      }
      if (alpha<=0) {
        dir=1;};
      for (int contador=0;contador<600;contador=contador+1) {
      float angulo=random(0,TWO_PI);
      float x=200*cos(angulo);
      float y=200*sin(angulo);
      
      float angulo2=random(0,TWO_PI);
      float x2=200*cos(angulo2);
      float y2=200*sin(angulo2);
      
      line (x+250,y+250,x2+250,y2+250);}
      
      }
    
    					

    A.Interface

    To achieve the interface between processing and an actuator I decided to make the movement of a servomotor, as a communication taking an Arduino Uno. To achieve this goal the physical elements are: • Arduino UNO • Micro Tower Pro Servo 9g • Interconnect Cables • Communication Cables • Computer In terms of software to be downloaded in the Arduino Uno Standart Firmata Firmware is a generic protocol to communicate with microcontrollers a central computer software. Once downloaded the firmware on the Arduino Uno is no longer need the Arduino IDE to perform another action. Processing level after the following script is developed:

    import processing.serial.*;
    import cc.arduino.*;
    Arduino arduino;
    void setup() {
      println(Arduino.list());
      arduino = new Arduino(this, Arduino.list()[0], 57600);
      arduino.pinMode(4, Arduino.SERVO);
    }
    void draw() {
      rect (25, 25, 50, 50);
      if (keyPressed == true){
        arduino.servoWrite(4, 180);
        fill(0);
      }
      else {
        arduino.servoWrite(4,0);
        fill(255);
      }
    }
    
    
    					


    This script does is in principle import libraries serial communication and Arduino, then establish communication identifying the USB port which is physically connected to the communication cable between Arduino and the computer, and connected sets processing the signal output pin for the servomotor to continue with the corresponding functions as keyPressed, servoWrite. The sequence indicates that while we press any keyboard character servo swivel from 0 ° to 180 ° position when we returned to zero pressing angle.
    We obtain:

    Enjoy!

    Downloading link for my archives:
    Archives