|
楼主 |
发表于 2019-1-15 17:54:58
|
显示全部楼层
本帖最后由 eddiewwm 于 2019-4-1 15:02 编辑
使用 Processing範例
//How to upload an arduino sketch from java / processing?
// https://arduino.stackexchange.co ... rom-java-processing
import java.io.*;
void setup(){
String ArduinoPath = "C:\\Users\\User\\Desktop\\8F328U_Upload_Hex";
String hexPath = "C:\\Users\\User\\Desktop/8F328U_Upload_Hex/upload.hex";
String port = "COM8";
runCommand(new String[]{ArduinoPath+"/bin/avrdude", "-C"+ArduinoPath+"/avrdude.conf","-v","-patmega328p","-carduino","-PCOM8","-b57600","-D","-Uflash:w:"+hexPath+":i"});
}
void runCommand(String[] cmd){
String s = null;
try {
Process p = Runtime.getRuntime().exec(cmd);
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
// read the output from the command
System.out.println("command out:\n");
while ( (s = stdInput.readLine ()) != null) System.out.println(s);
System.out.println("errors (if any):\n");
while ( (s = stdError.readLine ()) != null) System.out.println(s);
}catch (IOException e) {
System.out.println("something went wrong: \n");
e.printStackTrace();
}
}
void draw() {
// line(mouseX, mouseY, 50, 50);
delay(2000);
background(0);
text("Job Done!!!", 0, 20);
// exit();
text("Press mouse key to End", 0, 40);
}
void mousePressed() {
exit();
}
|
|