Skip to content

Instantly share code, notes, and snippets.

@renatocantarino
Last active December 20, 2015 23:59
Show Gist options
  • Save renatocantarino/6217099 to your computer and use it in GitHub Desktop.
Save renatocantarino/6217099 to your computer and use it in GitHub Desktop.
Processin com Arduino
import java.*;
import java.io.*;
import processing.serial.*; //Cria o canal de comunicação com o Arduino
import cc.arduino.*; //Libs Arduino
Arduino arduino;
int ledPin;
void setup()
{
arduino = new Arduino(this, Arduino.list()[1]);
ledPin= readData("C://dt.txt");
arduino.pinMode(ledPin, Arduino.OUTPUT);
}
int readData(String myFileName){
File file=new File(myFileName);
StringBuffer contents = new StringBuffer();
BufferedReader br=null;
int retorno=0;
try{
br=new BufferedReader(new FileReader(file));
String text=null;
while((text=br.readLine())!=null){
String [] subtext = splitTokens(text,",");
retorno = int(subtext[0]);
return retorno;
}
}catch(FileNotFoundException e){
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}finally{
try {
if (br != null){
br.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return retorno;
}
void draw()
{
arduino.digitalWrite(ledPin, Arduino.HIGH);
delay(1000);
arduino.digitalWrite(ledPin, Arduino.LOW);
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment