Wednesday, October 20, 2010

read value from one analog input in Processing

import processing.serial.*;

Serial port;
float val;

void setup() {
size(800, 600);
String arduinoPort = Serial.list() [0];
port = new Serial(this, arduinoPort, 9600);
}

void draw() {
if (port.available() > 0) {
val = port.read();
// val = map(val, 0, 255, 0, height);
}

background(val);
}

read one analog input in Arduino

const int firstPin = A0; // sensor to control value on analog input 0


void setup()
{
Serial.begin(9600);
}

void loop()
{
Serial.print(analogRead(firstPin));
}