We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey guys, I have code that uses a button and when pressed will switch on an LED(which will stay on) and then when the button is pressed again, the LED is turned off. I have connected the Arduino and Processing using Standard Firmata successfully and the LED works.
What I want to be able to do is that when the button is pressed, an image will show up in Processing but also stay on the screen, just like the LED. I'm just testing it with shapes for now. I would really appreciate your help. This is what I have so far:
import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
int buttonPin = 7;
int buttonState = 0;
int buttonPressed = 0;
void setup(){
size(600, 600);
println(Arduino.list());
arduino = new Arduino(this, Arduino.list()[6], 57600);
arduino.pinMode(buttonPin, arduino.INPUT);
}
void draw()
{
buttonState = arduino.digitalRead(buttonPin);
if (buttonState == arduino.HIGH && buttonPressed == 0)
{
buttonPressed = 1;
rect(10, 10, 10, 10);
text("hello", 10, 10);
}
if (buttonState == arduino.LOW && buttonPressed == 1)
{
buttonPressed = 0;
rect(50, 50, 10, 10);
}
}
Answers
You can use following lines in place of shapes.
Hope this would help you.
hi....i am new and only familiar with processing. Arduino is totally new for me. You already worked wit data from arduino to manupilate an image in processing? is it possible to give me an example from arduino and how to import data in processing. I want to use the sensor HC-sr 04 in arduino to let move images in processing. I hope you can help me to go on.