We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello I have been having some struggles with displaying flowers on my Android. This is what my code does. I have two sensors on the Arduino, photoresistor and motion detector, they both work and what Processing does is to display different modes of a colored flower based on the state of the sensors. I want to create a sort of energy conscious display so people know what is wrong in a room based on the color of the flower. A connection between Processing and Android works(only a test of flower display), so does the connection between Processing and Arduino work(it runs and I see the flower states). How can I get the Android to display my flowers, it seems to me the problem might be from reading the Serial connections....any help?
Android Sketch
#define PIR 3
#define LED 2
int pirState;
int ldrValue;
void setup() {
Serial.begin(9600);
pinMode(LED, OUTPUT);
pinMode(PIR, INPUT);
digitalWrite(LED, LOW);
}
void loop(){
pirState = digitalRead(PIR);
ldrValue = analogRead(LDR)/4;
Serial.write(pirState);
Serial.write(ldrValue);
delay(1000);
}
Processing Sketch //
import processing.serial.*;
Serial port; // Create object from Serial class
int pirState;
int ldrValue;
void setup(){
fullScreen();
noStroke();
frameRate(15);
printArray(Serial.list());
port= new Serial(this, Serial.list()[0],9600);
}
void draw(){
if (port.available() > 0) { // If data is available to read,
pirState = port.read();
ldrValue = port.read(); // read it and store it in val
println(pirState, "and", ldrValue);
delay(10);
}
background(255); // Clear background
//set center point
translate(width/2, height/2);
//rotate canvas using frame count
// rotate(radians(frameCount+mouseX));
//draw 5 petals, rotating after each one
for(int i=0; i<5; i++){
if (pirState == 0 && ldrValue <= 128) { // no one is in and light is off
fill(#00ff00);//green
ellipse(0,-80,100,100);
rotate(radians(72));
println("no one is and light is off");
}
else if(pirState == 0 && ldrValue > 128){//no one is in and light is on
fill(#FF0000);//red
ellipse(0,-80,100,100);
rotate(radians(72));
println("no one is and light is on");
}
else if(pirState == 1 && ldrValue > 128) { // one is in and light is on
fill(#FFAA0D);//orange
ellipse(0,-80,100,100);
rotate(radians(72));
println("one is and light is on");
}
else if(pirState == 1 && ldrValue <= 128){ //if one is in and light is off
fill(#00AAFF);//blue
ellipse(0,-80,100,100);
rotate(radians(72));
println("one is and light is off");
}
//center circle
fill(#fff9bb);
ellipse(0,0,100,100);
}
How can I connect my Processing output to the Android.