Constantly reading from text file

edited December 2017 in Arduino


I'm trying to get my arduino to constantly read data from a text file. So far I managed to get it to read the text file upon a mouse click every time, using the "mousePressed()" function.

Problem: I am now trying to let it send data whenever the text file is APPENDED with new alphabets. Meaning to say only newly added data in the text file will be sent to Arduino. Can someone guide me on how to modify my code such that it constantly reads my text file, and sends newly added data?

`import processing.serial.*;

Serial comPort; int counter=0; // Helps to keep track of values sent. int numItems=0; //Keep track of the number of values in text file boolean sendStrings=false; //Turns sending on and off StringLoader sLoader; //Used to send values to Arduino boolean flag = true;

void setup(){ comPort = new Serial(this, "COM3", 9600); background(255,0,0); //Start with a Red background }

void draw(){

void mousePressed() { //Toggle between sending values and not sending values //sendStrings=!sendStrings;

//If sendStrings is True - then send values to Arduino if(sendStrings){ background(0,255,0); //Change the background to green

/*When the background is green, transmit text file values to the Arduino */ sLoader=new StringLoader(); sLoader.start(); }else{ background(255,0,0); //Change background to red //Reset the counter //counter=0; } sendStrings=false; }

/============================================================/ /* The StringLoader class imports data from a text file on a new Thread and sends each value once every half second */ public class StringLoader extends Thread{

public StringLoader(){ //default constructor }

public void run() { String textFileLines[]=loadStrings("../Directions.txt");

String lineItems[]=splitTokens(textFileLines[0], ",");


for(int i = counter; i<numItems; i++){








Sign In or Register to comment.