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 & HelpSyntax Questions › key press example
Page Index Toggle Pages: 1
key press example (Read 996 times)
key press example
Jan 3rd, 2008, 3:04am
 
hi, im a noob at processing, and i just found out how wounderfull the language is to use with arduino, becuase it opens up many more possibilities, and i'm having problems doing my first project.

i'm trying to make it so when i press a button on my keyboard, an led will turn on. But i'm getting several problems, most saying that "void" does not belong in the place i put it.

now this code IS NOT ANYWHERE NEAR THE CODE I WANT, this is simply an output test for the arduino, but i really don't know how to layout the language so it does not interfear with the arduinos translation to using processing.
if anybody could please fix up the code, and compile it to see if it works, because i cant get what im trying, so if anybody could just make it really quick, i would greatly apreciate it, heres the sample output code:



import processing.serial.*;

import cc.arduino.*;

Arduino arduino;

color off = color(4, 79, 111);
color on = color(84, 145, 158);

int[] values = { Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW,
Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW,
Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW };

void setup() {
 size(470, 200);
 
 println(Arduino.list());
 arduino = new Arduino(this, Arduino.list()[0], 57600);
 
 for (int i = 0; i <= 13; i++)
   arduino.pinMode(i, Arduino.OUTPUT);
}

void draw() {
 background(off);
 stroke(on);
 
 for (int i = 0; i <= 13; i++) {
   if (values[i] == Arduino.HIGH)
     fill(on);
   else
     fill(off);
     
   rect(420 - i * 30, 30, 20, 20);
 }
}

void mousePressed()
{
 int pin = (450 - mouseX) / 30;
 
 if (values[pin] == Arduino.LOW) {
   arduino.digitalWrite(pin, Arduino.HIGH);
   values[pin] = Arduino.HIGH;
 } else {
   arduino.digitalWrite(pin, Arduino.LOW);
   values[pin] = Arduino.LOW;
 }
}




please just change it so i get the desired effect, thanks and happy new years!
-big93
Re: key press example
Reply #1 - Jan 3rd, 2008, 10:30pm
 
can anybody help?

if anybody knows anything, PLEASE TELL ME!
if nobody knows about processing / arduino, how are people that like arduino sapposed to like processing, help our community help yours!

if you dont know how to do that, lets just say you want to turn an led on over serial, lets say pin 13, just get me that code and ill try to interface it.
Re: key press example
Reply #2 - Jan 3rd, 2008, 11:22pm
 
I can't speak for other people, but I personally don't like posts of this sort: "fix this, quick!". Probably that's why nobody answered!

The code you posted is an example included in the arduino-processing library, right? If so, try to get it to work before changing it. 'Cause if it doesn't work, something has not been correctly setup. There are many places where the bug could be:
Adruino: Does it have the "firmdata" firmware on it?
Arduino: is it connected to the computer?
Computer: Is the Arduino driver installed?
Computer: Nothing but processing is accessing the serial port? (e.g. no open serial monitor in the ArduinoIDE)
Processing: Did you install the Arduino-Library correctly?
Processing: Does Arduino.list() print out any Arduino?

If you have the example working, go and have a look at http://processing.org/reference/keyPressed_.html it's gonna be easy to change your example code to work with key press.
Re: key press example
Reply #3 - Jan 5th, 2008, 6:13pm
 
thanks, but i know everything works, and everything is installe,d i ran the test output programs, and it's just that everytime i make a sktch with the void draw and then the key pressed, it sais that void does not belong there, even though it does!
Re: key press example
Reply #4 - Jan 5th, 2008, 6:18pm
 
ah ok, i see. there is a missing curly bracket after your for-loop in setup.
Page Index Toggle Pages: 1