Hi,
I am trying to pass a variable called elapsedTime (line 20.) from an Ardunio sketch to a Processing sketch. I know in the Processing I can't read into a float like this. A float is 4 bytes and a read reads one byte. (line 3 of the Processing sketch)
Any help would be greatly appreciated.
Thanks,
Shane
I am trying to pass a variable called elapsedTime (line 20.) from an Ardunio sketch to a Processing sketch. I know in the Processing I can't read into a float like this. A float is 4 bytes and a read reads one byte. (line 3 of the Processing sketch)
The Ardunio code is as follows,
- int ledTX = 12; //Receives InfraRed signal
- int photodiodePin = 2; // Photodiode connected to digital pin 2
- int lastState;
- unsigned long startTime;
- unsigned long elapsedTime;
- void setup() {
- Serial.begin(9600);
- pinMode(ledTX, OUTPUT);
- pinMode(photodiodePin, INPUT); // sets the digital pin as input to read photodiode
- }
- void loop() {
- byte currentState = digitalRead(photodiodePin);
- digitalWrite(ledTX, HIGH); // turn the TX Infrared LED on
- if(currentState == LOW && lastState == HIGH){
- startTime = millis();
- }
- if(currentState == HIGH && lastState == LOW){
- elapsedTime = millis() - startTime;
- Serial.println(elapsedTime);
- Serial.write(elapsedTime);
- }
- lastState = currentState;
- }
- import processing.serial.*;
- Serial port;
- float elapsedTime;
- void setup() {
- size(200, 200);
- background(204);
- noStroke();
- port = new Serial(this, 9600);
- }
- void draw() {
- if (0 < port.available()) {
- elapsedTime = port.read();
- }
- println(elapsedTime);
- }
Any help would be greatly appreciated.
Thanks,
Shane
1