We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpElectronics,  Serial Library › Using processing to control LED
Page Index Toggle Pages: 1
Using processing to control LED (Read 2707 times)
Using processing to control LED
Mar 8th, 2006, 10:19am
 
Hi all, this may seem like a stupid question but i am just starting out.

i have processing and wiring, and a wiring board. i want to use processing to control LED's on my wiring board. i want to make a processing interface (two buttons, On and Off) to turn an LED on/off on the wiring board.

but now i have no idea the process to do this. could some one please provide me with a solution. i would like to know how to go from: Processing > to > Wiring > to > Wiring board

once i know this i think i will be able to do it again. but right now i have no idea how to start.

Could someone please help out in simple steps if possible. Thanks guys
Re: Using processing to control LED
Reply #1 - Jun 6th, 2006, 2:22am
 
Just to clarify: The wiring programming environment doesn't actually RUN the program, it simply compiles it and then loads it into the microprocessor on the wiring board.  So, you really want to do this:

Processing -> Wiring Board

To connect processing and the wiring board you will probably want to use the serial communication libraries.  To make a light turn on and off, I would recommend just sending a single byte from processing whenever the user pushes a button (like: 0 == off, 1 == on).

To send bytes via processing, check out the serial library reference:
http://www.processing.org/reference/libraries/serial/Serial_write_.html

Then, in wiring write code to watch the serial port and update the LED state any time data is available.  Here is some *slightly* modified code taken from http://www.wiring.org.co/reference/libraries/Serial/Serial_available_.html

(also, I'm not at home so I can't test this to make sure it works..)
Code:

int val;
int LED_PIN = 4;

void setup() {
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600);
}

void loop() {
if( Serial.available() > 0) {
val = Serial.read();
}

if(val == 0)
digitalWrite(LED_PIN, LOW);
else
digitalWrite(LED_PIN, HIGH);
}
Re: Using processing to control LED
Reply #2 - Jun 19th, 2006, 4:46am
 
Using my Phidgets library ( http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Contribution_Physical;action=display;num=1150684082 )

you can control LEDs over USB/Processing as simply as:
PhidgetsIFK p=new PhidgetsIFK();
p.output(0,true); //turn output 0 on
delay(500); //wait half a second
p.output(0,false); //turn output 0 on

But you'll need a phidgetsInterfaceKit (phidgets.com)
Re: Using processing to control LED
Reply #3 - Apr 11th, 2007, 12:54pm
 
Hey all!
What would you guys recommend in my case, where I'd like to control a bunch of LEDs with variable luminance (0-255)?
Thanks Wink
Page Index Toggle Pages: 1