mardi 29 septembre 2015

Arduino+processing and string information in an "if" statment

I am using an arduino to read out information from a scale into Processing. Now I want certain things to happen depending on the weight registered. The weight is read out in a String. I have found out that ">=" does not work for strings. I have tried "if (val >= str ("20.00")){" but that doesnt work either. I have also tried to convert it into a float using "float scale = Float.parseFloat(val);" But that doesnt work either. Does anyone have an idea. That would be great!

PImage pictureday;
import processing.serial.*;
import cc.arduino.*;
import org.firmata.*;

Serial myPort;  
String val;     
color textcolor = color(0, 50, 50, 240);
color textcolor2 = color(255, 0, 0); 

void setup()
{
  fullScreen();
  background (189, 215, 239);
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);
}

void draw()
{
  if ( myPort.available() > 0) 
  {  // If data is available,
    val = myPort.readStringUntil('\n'); 
  } 

  if (scale >= 20.00)
  { 
    image(pictureday, 0, 0);  
    textSize(50);
    fill(textcolor);
    text(val, 900, 360);
    text("KG ", 1030, 360);  
    println (val);
  }
}

Aucun commentaire:

Enregistrer un commentaire