Hello everyone Im kinda new to Processing, but I have to finish my Final project in the final year in uni :). What I am trying to do is to create a windmill on which there are 3 LED's attached on. Those LED's are controlled from xml feed and depending wind speed they glow(something like a glowing meter). I've managed to extract the exact data i needed from the xml(i got string numbers from the xml so I know which part of the line on which string number is so I can call just wind speed and I've transfered it into int) and etc, but when I try to make the if statement it doesn't do as said. So far I've plugged only 1 LED on 1 pin of the arduino, but as soon as it starts working with the if statement i will attach 2-3 more. Please take a look where Is my mistake, because i have like 5 days left :D
The code:
// Array to store titles
String[] titles;
import processing.serial.*;
PFont font;
import cc.arduino.*;
Arduino arduino;
int ledPin = 13;
Serial myPort;
int speed;
void setup() {
size(700, 300);
background(0);
noStroke();
//println(Arduino.list());
arduino = new Arduino(this, Arduino.list()[0], 57600);
arduino.pinMode(ledPin, Arduino.OUTPUT);
// Setup font
font = createFont("Arial", 12);
textFont(font, 12);
// xml = loadXML("http://weather.yahooapis.com/forecastrss?w=27764362");
String[] xml = loadStrings("http://weather.yahooapis.com/forecastrss?w=27764362");
println("Weather read");
int i = 0;
for (; i < xml.length; i++)
{
if (xml[i].contains("yweather:wind"))
break;
}
if (i == xml.length)
{
println("Not found");
exit();
}
String[] info = xml[i].split("\\W+"); // Split on everything not alphanumerical
println(info);
titles = new String[3];
for (int j = 0; j < info.length; j++)
{
if (info[j].equals("chill")) titles[0] = "chill = " + info[j+1];
if (info[j].equals("direction")) titles[1] = "direction = " + info[j+1];
if (info[j].equals("speed")) titles[2] = "speed = " + info[j+1];
}
println(Serial.list());
speed = int(info[8]);
speed = Integer.parseInt(info[8]); // No "int" part, not a declaration, just an assignment
println(""+ speed);
}
void loop() {
if (speed > 5)
arduino.digitalWrite(ledPin, Arduino.HIGH);
delay(500);
}
So lets say the xml value for "speed" is 10 and i make the statement to turn the LED if its more than 5. It should work, but nothing happens :(
Big thanks
Nick