Last active
December 20, 2015 23:59
-
-
Save renatocantarino/6217099 to your computer and use it in GitHub Desktop.
Processin com Arduino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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