Interface and application programming

Week 16

Choossing a language

Well, all those languages look very aliens and hard to master to me, so it is hard to choose a tool based on my own knowledge. I would way that I'm definitely attracted to the ones that Neil suggested (Python and Java) but, I've been introducing myself to the Arduino world from the beginning of this program so there's a part of me that'd like to continue into that direction. Til now, I've found the Arduino's tools very nice to use and also very well documented. So, I'll begin with Processing that and try, if I have the time with one of the two other proposed languages.

Also, for that assignment, I have to connect it with and other one weather it's input or output week. Well, I'll do it with my input week because I thought it'd be very fun to see a graphic representation of the potentiometer and a priori, it seemed very well documented too and I'll need that extra help!

The board

This is a funny thing to think but I don't have a board making process to present because I used the one I made for my input devices week ! It seemed a little empty but I guess I'll deal with that easily :p. Just as a remembering, here's the board I'll use.

The code for Arduino IDE

As the main end funtion of this board will be a little different, I have to change the main code within that input devices week board. To do that, I had to understand some specific funtion of Arduino code and aslo it's relation with the other sofware (Processing) :

Here's the code I came up with :

											
#include <.SoftwareSerial.h>
const int rx=-1;
const int tx=1; //miso pin
SoftwareSerial mySerial(rx, tx);
void setup() {
// initialize the serial communication:
 mySerial.begin(4800);
}

void loop() {
// send the value of analog input 0:
mySerial.write(analogRead(2));
// wait a bit for the analog-to-digital converter
// to stabilize after the last reading:
delay(20);
}
											
											

The code for Prossing

Now switching on Processing, which in completly new to me, I had to understand some other fuction of the program before to begin to code something as for the Serial library :

"The Serial library reads and writes data to and from external devices one byte at a time. It allows two computers to send and receive data. This library has the flexibility to communicate with custom microcontroller devices and to use them as the input or output to Processing programs. The serial port is a nine pin I/O port that exists on many PCs and can be emulated through USB." Source : Processing

Adding to this specific library, it was recommended to learn some more other function to make what I wanted to happen :

After all that learning, I was able to generate and addapt a code for my project. Here's it is :

import processing.serial.*;
Serial myPort;
int value;
int padding = 100;
float m;

void setup() {
size(1440, 900);
println("Available serial ports:");
println(Serial.list());
myPort = new Serial(this, Serial.list()[1], 4800);
smooth();
strokeWeight(3);
stroke(100);
}

void draw() {
background(#FFFFF0);
if (myPort.available() > 0) {
value = myPort.read();
println(value);
m = map(value, 255, 0, padding, width-padding);
}
line(padding, height/2, width-padding, height/2);
noStroke();
fill(#FFDE14);
ellipse(m, height/2, 150, 150);
stroke(100);
}
													

Final result

There it is ! This is so satisfiyng to see interaction with a board directly in the screen ! There's a video of it !