<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with float() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=float%28%29</link>
      <pubDate>Sun, 08 Aug 2021 18:47:56 +0000</pubDate>
         <description>Tagged with float() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedfloat%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>android serial usb arduino hiccups?</title>
      <link>https://forum.processing.org/two/discussion/24989/android-serial-usb-arduino-hiccups</link>
      <pubDate>Mon, 13 Nov 2017 16:54:07 +0000</pubDate>
      <dc:creator>vagos21</dc:creator>
      <guid isPermaLink="false">24989@/two/discussions</guid>
      <description><![CDATA[<p>Hello everyone, i've been working with processing and the android mode for a few days now, and i decided to do this little sensors report when i plug in my android phone to my arduino. i set up the manifest with the vendor IDs and everything and it all works fine but...</p>

<p>even though the arduino Tx lights up continuously (sends data all the time) the processing software looks like it's getting data for a couple of seconds, then looks completely idle for 10 seconds, then takes data again, then no comminucation again... i know the app is not freezing because i'm doing a sliding graph, which happily slides along. any idea what could be causing this hiccup? a buffer overrun?</p>

<p>to be honest i'm trying to make something like a semi-fast DMM, and right now the arduino sends 2 values every 100ms, <a href="/two/profile/38400">@38400</a> baud. is this too fast for the app to handle?</p>

<p>forgive me for the following, but i can't find a code format button...? :D</p>

<p>this is the arduino code:</p>

<pre><code> void setup() {
   Serial.begin(38400);
   pinMode(A0,INPUT);
   pinMode(A1,INPUT);
}

void loop() {
  Serial.print(analogRead(A0));
  Serial.print(";");
  Serial.println(analogRead(A1));
  delay(150);
}
</code></pre>

<p>and the android side:</p>

<pre><code>import io.inventit.processing.android.serial.*; //ANDROID

//SERIAL PORT
Serial myPort;      //thermostat serial port
String inString=""; //input string from serial port

//FONTS
PFont dateFont;           //date font

//REALTIME DATA
float v1 = 0.0;  //voltage1
float v2 = 0.0;  //voltage2

//COLORS
color activeText = color(182, 230, 244);
color inactiveText = color(60, 60, 60);

//BUTTONS
transButton resetBtn = new transButton( width/2, height-50, 200, 50, "Reset");


void setup() {
  fullScreen();
  orientation(LANDSCAPE);
  frameRate(200);

  //init fonts
  dateFont = createFont("WalkwayBold.ttf", 60);

  //init USB serial port
  myPort = new Serial(this, Serial.list(this)[0], 38400); //ANDROID
  myPort.bufferUntil(10);
}

//===========INCOMING DATA FROM THERMOSTAT=============
void serialEvent(Serial myPort) { 
  try {
    inString = myPort.readString();
    String[] list = split(inString, ';');
    v1 = float(list[0])/1024.0;
    v2 = float(list[1])/1024.0;
  }
  catch(RuntimeException e) {
    e.printStackTrace();
  }
}

//===============MAIN LOOP===================
void draw() {
  //timeNow = millis();
  drawMainScreen();
}


//===============DRAWING LOOP===================
void drawMainScreen() {
  background(36,93,142);

  //voltage 1
  fill(255);
  textFont(dateFont);
  textAlign(LEFT, CENTER);
  text("v1: " + v1 + "V", 50, 20);

  //voltage 2
  fill(255);
  textFont(dateFont);
  textAlign(LEFT, CENTER);
  text("v2: " + v2 + "V", 50, 80);

  //raw serial input
  fill(255);
  textFont(dateFont);
  textAlign(CENTER, TOP);
  text("raw: " + inString, 700, 20);
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to read from a text file to arraylist of pvectors</title>
      <link>https://forum.processing.org/two/discussion/20185/how-to-read-from-a-text-file-to-arraylist-of-pvectors</link>
      <pubDate>Tue, 10 Jan 2017 23:30:26 +0000</pubDate>
      <dc:creator>zackcoder2</dc:creator>
      <guid isPermaLink="false">20185@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I have a text file having data in the form of:</p>

<p>x &amp; y co-ordinates:</p>

<pre><code>880.4895 373.5595

797.7594 551.85364

582.87476 590.6258
</code></pre>

<p>in each line, i have to store these 3 lines in a arraylist of pvector each having x &amp; y co-ordinates
arraylist of size 3.</p>

<p>Can you please give me a sample code on how to split and load this data into arralist of pvectors.</p>

<p>Thanks in advance.</p>
]]></description>
   </item>
   <item>
      <title>Load, read and exploit .DAT file</title>
      <link>https://forum.processing.org/two/discussion/17596/load-read-and-exploit-dat-file</link>
      <pubDate>Wed, 20 Jul 2016 15:58:53 +0000</pubDate>
      <dc:creator>benoitfl</dc:creator>
      <guid isPermaLink="false">17596@/two/discussions</guid>
      <description><![CDATA[<p>Hello Every-one,
first message here, I do need some help on that, I'm sure it's quite simple but I've been struggling a lot on that recently "grrrr"  ~X(</p>

<p>I have a .DAT file witch comport a list of airport and coordonates of these.</p>

<p>Easy I want to "look for" a certain airport and gets its coordonates back.</p>

<p>The format of the file is :ZZZZCORDONATEX CORDONATEY<br />
My problem is that sometimes I got 2 spaces in between values and then got a "shifting" and mess up my values(By the way I'm sure that is the problem). I don't have any more code since I didn't get it to work as its design  :(|)  :(|)</p>

<p>This file is quite big about 13k lines.
here is an example of the file.</p>

<pre><code>"CYGB 49.694167-124.517778
EDFU 49.695000   9.182000
LKMT 49.696111  18.110833
CJE3 49.697495-103.800722
ETIC 49.698686  11.940175
CEY3 49.700000-113.416667
CKJ7 49.706053 -97.680525
EGJA 49.706758  -2.214481
CYQQ 49.710833-124.886667
"
</code></pre>

<p>thanks for the help !</p>

<p>Flo</p>
]]></description>
   </item>
   <item>
      <title>Most Efficient Conversion of Integer Value to Floating Point Value</title>
      <link>https://forum.processing.org/two/discussion/14169/most-efficient-conversion-of-integer-value-to-floating-point-value</link>
      <pubDate>Mon, 28 Dec 2015 17:05:45 +0000</pubDate>
      <dc:creator>Jim_Plaxco</dc:creator>
      <guid isPermaLink="false">14169@/two/discussions</guid>
      <description><![CDATA[<p>Note this is not a question about casting.</p>

<p>I am curious as to the most efficient way to take an integer value and convert it to a floating point so that the whole numbers become fractional numbers.</p>

<p>To illustrate, I want to convert any number from 99999  to  0.99999. 
So if the value is 7 I want the output to be 0.7. 
If the value is 8412223,  I want the output to be 0.8412223</p>

<p>Is there some "magic" bit-oriented operation that can achieve this or will it take a brute-force method (for example determine the number of digits in the value and then divide by an equivalent power of 10).</p>

<p>Any insights will be greatly appreciated. Thanks</p>
]]></description>
   </item>
   <item>
      <title>How to transform String in float :  float value = float(cm); ? Help</title>
      <link>https://forum.processing.org/two/discussion/14085/how-to-transform-string-in-float-float-value-float-cm-help</link>
      <pubDate>Sun, 20 Dec 2015 13:27:47 +0000</pubDate>
      <dc:creator>dmada</dc:creator>
      <guid isPermaLink="false">14085@/two/discussions</guid>
      <description><![CDATA[<p>Hi everyone,</p>

<p>Currently I make a project for learn how to discuss between sensor and processing.
So Processing read correctly the port of arduino ( I can see the value with processing)</p>

<p>My problem it's a cannot use this data for make something ( example I want to hide or show like influenced the opacity of an picture). For influenced the opacity I use a white rect but maybe is not a good idea.</p>

<p>Because ( maybe) I've string informations and for make a "if" I use a float .
I search differents things but i'm lost with the differents method to are not very clear. 
I search to transform "cm" in float var1 for use my if. After I thinking to make a map for transform the data.</p>

<pre><code>        // the code with proximity sensor and "cm" like string value. 


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

        Serial myPort;   
        String cm;
        float var1;
         PImage fonds;


        void setup() {

           size(displayWidth, displayHeight); //full screen
          println(Serial.list());
          myPort = new Serial(this, Serial.list()[6], 9600);  // go to read the COM of arduino
         myPort.bufferUntil('\n');
          fonds = loadImage("testu.jpg");
           image(fonds, 0, 0,displayWidth,displayHeight); 

        }

        void draw() {


        while (myPort.available() &gt; 0) { //Continue usb serial
            String cm = myPort.readStringUntil('\n'); // Read port analog
            if(cm!=null) {
             cm = trim(cm);

              float var1 = float(cm); // The problem is here how to transform this value

               var1 = map (var1, 0, 700, 0, 255);
            println(cm); // affichage
            println(var1);

            }                       
        }
        if (var1 &gt; 100){                 // currently he don't read this part
         noStroke();
         fill(255,0);
        rect(0, 0,displayWidth,displayHeight);
        smooth();
        }

        else { 
           noStroke();
         fill(255,10);
        rect(0, 0,displayWidth,displayHeight);
        smooth();
        } 

        }
</code></pre>

<p>Sorry for my english if i make some mistake.
Thank's 
Kinds regards</p>
]]></description>
   </item>
   <item>
      <title>Unpacking UDP Packet - byte to float</title>
      <link>https://forum.processing.org/two/discussion/13598/unpacking-udp-packet-byte-to-float</link>
      <pubDate>Sun, 22 Nov 2015 13:26:25 +0000</pubDate>
      <dc:creator>potter3366</dc:creator>
      <guid isPermaLink="false">13598@/two/discussions</guid>
      <description><![CDATA[<p>I am receiving this message from another app via a udp socket (hypermedia.net). I'd like to convert message after blank to a floating point value.</p>

<p><em>receive: "56871833174353 -0.095239157733537" from 192.168.178.52 on port 50396</em></p>

<pre><code>void receive( byte[] data, String ip, int port ) {
  data = subset(data, 0, data.length-2);
  String message = new String( data );
  println( "receive: \""+message+"\" from "+ip+" on port "+port );
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Truncation of float with println</title>
      <link>https://forum.processing.org/two/discussion/13079/truncation-of-float-with-println</link>
      <pubDate>Sat, 17 Oct 2015 23:56:51 +0000</pubDate>
      <dc:creator>Haunted</dc:creator>
      <guid isPermaLink="false">13079@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I'm using processing to read in GPS data from a wireless sensor, over serial. I'm finding that converting the float to a string and then displaying it is leading to a loss of precision that is unacceptable for precise GPS. In fact, just printing a long float in Processing, or displaying it as text also causes truncation:</p>

<pre><code>  println(float("41.312320709"));
  println(41.312320709);
</code></pre>

<p>in both cases the output is 41.31232, so the '0709' at the end has been lost. Though the conversion may actually be converting the data to the correct precision, it's very hard to work with the truncated values.</p>

<p>I've also tried <code>Float.valueOf(f2_str).floatValue();</code> 
and <code>Float.parseFloat(f2_str);</code>
but when I println I get the same results.</p>

<p>I've checked the print reference but can't find an alternative format or explanation on why it is limited to a certain number of characters.</p>

<p>Any help appreciated.</p>
]]></description>
   </item>
   </channel>
</rss>