converting float to an int
in
Integration and Hardware
•
2 years ago
Hi guys, I'm new to processing and I have a problem converting a float to an int.
What my sketch is doing is getting a data from an XML feed & printing it as a float.
I am trying to interface it with Arduino to control a motor.
Any ideas??
Thanks in advance.
- import processing.serial.*;
- import cc.arduino.*;
- Arduino arduino;
- //setting up my pins
- int vibPin = 9;
- float[] magVal;
- int xx;
- int newMag;
- void setup() {
- size(200, 200);
- arduino = new Arduino(this, Arduino.list()[0],57600); // creates an arduino object. the Parent is "this" the name is the name of the device, the rate of the speed is the baud rate.
- println(Arduino.list()); // prints a list of of available serial ports
- arduino.pinMode (vibPin, Arduino.OUTPUT);
- }
- void draw() {
- float[] magVal = getMag(); // gets the latest earthquake reading.
- int xx = magVal.length;
- println(magVal[xx-1]);
- delay(1000*30); // will search for a new earthquake every 30seconds
- int byten = 10;
- newMagVal = int (magVal*byten);
- print (newMagVal);
- if (magVal < 255)
- {
- arduino.digitalWrite(vibPin, Arduino.LOW);
- }
- };
1