import processing.serial.*; //import serial library Serial port; String data; String fileName; int digit,number,row,letterGroup; // this array stores the characters that each number corresponds to String letter[] = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z",".","?"," ","(",")","@"}; String out[] = new String[540]; //string aray where numbers are stored int textLine; int total; boolean done; void setup() { //***CHANGE THE COM PORT TO WHICH EVER ONE YOUR ARDUINO IS CONNECTED TO*** port = new Serial(this, "COM7", 9600); //creates a new serial connection at 9600 baud port.bufferUntil('\n'); fileName = "OTP.txt"; //*** MAKE SURE YOU CREATE A TEXT FILE LABLED OTP.txt IN THE SKETCH FOLDER!!!*** } void serialEvent(Serial port) //when something is recieved over the serial port { if (done == false) //if number reading is still in progress { data = port.readStringUntil('\n'); //reads incoming serial data line by line total++; println(total); //display how many numbers have been generated so far if(float(data) == 1) // if the number is a one { number += pow(2,digit); // find the value of that bit in base 10 } digit++; // used to group them into 5 characters if(digit == 5) { digit = 0; //only count 10 digits row++; if(out[textLine] != null) { out[textLine] += letter[number]; //add the character to the output string //this part adds spacing, just for formating if(row == 5 || row == 10 || row == 15 || row == 20 || row == 25 || row == 35 || row == 40 || row == 45 || row == 50 || row == 55) { out[textLine] += " "; }else if(row == 30) { out[textLine] += " "; }else if(row == 60) { row = 0; saveStrings(fileName, out); //save the numbers every row textLine++; if(textLine > 539) // make 540 lines (10 pages) { done = true; //tell the program to stop collecting numbers } } }else{ out[textLine] = letter[number]; } number = 0; } } } void draw() { }