import processing.serial.*; import java.io.*; Serial myPort; int mySwitch; String transmitter[] = new String[1280000]; //initialize array void setup(){ mySwitch=1; //Open the serial port for communication with the Arduino //Make sure the COM port is correct myPort = new Serial(this, "COM6", 9600); myPort.bufferUntil('\n'); } void draw() { if(mySwitch == 1) { readData("input.txt"); int index = 0; while(index < 128000) { myPort.write(transmitter[index++]); if(index%128 == 0) delay(100); } } mySwitch = 0; } void readData(String myFileName){ File file=new File(myFileName); BufferedReader br=null; try{ br=new BufferedReader(new FileReader(file)); String transmit=null; int i = 0; /* keep reading each line until you get to the end of the file */ while((transmit = br.readLine()) != null) transmitter[i++] = transmit; }catch(FileNotFoundException e){ e.printStackTrace(); } catch(IOException e){ e.printStackTrace(); } finally{ try { if (br != null) br.close(); } catch (IOException e) { e.printStackTrace(); } } } In the above code, I have an String array and I'm reading lines from a file and saving them as strings. How would I save them as byte/char inside an array of byte/char?
Basically, I have a file of integers on each line, each integer in the range [0, 255]. And I want to read this integer and send it to the Arduino. The Arduino serial.read() function reads a byte at a time. This is the issue I am trying to solve.