Mini NES

Posted on November 23rd, 2008 in Tech test2

haha this is so awesome and funny. You have to check it out!

From make via technabob

I used to have this naive thinking that reading a sensor input from arduino is just a few lines of codes that I can copy and paste over and over again , probably because I worked with quite a lot of sensors in my last project “portable windows” as well, but for portable windows I was doing everything in arduino. So when I really wanted to start bringing in a few different input from the same port, I was completely stoned. Thankfully, I got myself a copy of “Making things work” by tom igoe and I saved myself back there. So i’m going to share this code with everyone, I modified it a little, its all about assigning variables so it should be easy. I would love to help if anyone needs any (not that i’m good) , but i’ll try.

here goes : processing.

import processing.serial.*;

int linefeed = 10;
Serial myPort; // The serial port

int one, two, three, four, five;

void setup()
{
size(512, 200);
// always start Minim first
println(Serial.list());

myPort = new Serial(this, Serial.list()[0], 9600);
myPort.bufferUntil(linefeed);

}

void draw(){

background(0);
if(two>0){
five=two;

}
else{
two=five;
}
println(”five =”+five);
delay(1000);
}

void serialEvent(Serial myPort){
String myString = myPort.readStringUntil(linefeed); //the ascii value of the “|” character
if(myString != null ){
myString = trim(myString);
int sensors[] = int(split(myString, ‘,’));
//now assign your values in processing

if (sensors.length == 4){

one = sensors[0];
two = sensors[1];
three = sensors[2];
four = sensors[3];

println(”one =”+one);
println(”two =”+two);
println(”three =”+three);
println(”four =”+four);

}

}

}

For arduino’s part, its per normal but when you do a serial print u need to add a “,” after each sensor’s data. And after the last println it should end with a “|” println. What this does is that it recognises every data as an input denoted by the comma and ends every loop with an “|”.

Example :

Serial.print(gas,DEC);
Serial.print(”,”);
Serial.println(retTemp, DEC);
// Serial.print(”|”);

hope that helps.