I am a bit confused, I was under the impression if I used the standard tx0, rx0 pins on the mega - the rx, tx pins on the Uno - with no additional hardware or different software protocols the maximum transmission distance should be somewhere around 15m.
Last night I conducted a test and managed 160m with no lost communications? How is this possible?
I used shielded CAT6 cable, a Baud rate of 9600
Project explanation: I am creating a Submersible ROV. There will be a PC running a Human interface program in Processing(.org). This will transmit and receive control information to a Arduino Mega over the standard USB serial connection. This Arduino Mega then retransmits these controls and receives feedback from the submersible ROV. The ROV will have 2 different Arduino Uno. This transmission distance will be 30-100m.
Sketch for the Mega
void setup() {
Serial.begin(9600); // enables the serial connection. Make sure it's the same on both sides (here in the Arduino IDE and in the Processing program)
Serial1.begin(9600); // enables the serial connection. Make sure it's the same on both sides (here in the Arduino Mega IDE sketch and in the Arduino Uno1 IDE sketch)
Serial2.begin(9600); // enables the serial connection. Make sure it's the same on both sides (here in the Arduino Mega IDE sketch and in the Arduino Uno2 IDE sketch)
}
/*
tx & rx is with respect to the Arduino Mega. Arduino Mega receives lowercase char on serial port 0 from the PC processing program.
It transmits these lower case char on serial port 1 or 2 to the Arduino Unos in the ROV. The Arduino Unos in the ROV then transmits a Upper
case char in responce to the recieved command. The Arduino Mega recieves this on serial port 1 or 2 and retransmits it on serial port 0 to the PC processing program.
*/
//tx_ functions to send the char recieved from the PC processing program to the ROV Arduino Uno1 or Uno2 program
//rx_ functions to send the char recieved from the ROV Arduino Uno1 or Uno2 program to the PC processing program
void tx_driveUp() {
//Serial.write('A');
Serial1.write('a');
}
void rx_driveUp() {
Serial.write('A');
//Serial1.write('a');
}
void tx_releaseDriveUp() {
//Serial.write('Z');
Serial1.write('z');
}
void rx_releaseDriveUp() {
Serial.write('Z');
//Serial1.write('z');
}
void tx_driveDown() {
//Serial.write('B');
Serial1.write('b');
}
void rx_driveDown() {
Serial.write('B');
//Serial1.write('b');
}
void tx_releaseDriveDown() {
//Serial.write('Y');
Serial1.write('y');
}
void rx_releaseDriveDown() {
Serial.write('Y');
//Serial1.write('y');
}
void tx_driveForward() {
//Serial.write('C');
Serial1.write('c');
}
void rx_driveForward() {
Serial.write('C');
//Serial1.write('c');
}
void tx_releaseDriveForward() {
//Serial.write('X');
Serial1.write('x');
}
void rx_releaseDriveForward() {
Serial.write('X');
//Serial1.write('x');
}
void tx_driveBackward() {
//Serial.write('D');
Serial1.write('d');
}
void rx_driveBackward() {
Serial.write('D');
//Serial1.write('d');
}
void tx_releaseDriveBackward() {
//Serial.write('W');
Serial1.write('w');
}
void rx_releaseDriveBackward() {
Serial.write('W');
//Serial1.write('w');
}
void tx_driveLeft() {
//Serial.write('E');
Serial1.write('e');
}
void rx_driveLeft() {
Serial.write('E');
//Serial1.write('e');
}
void tx_releaseDriveLeft() {
//Serial.write('V');
Serial1.write('v');
}
void rx_releaseDriveLeft() {
Serial.write('V');
//Serial1.write('v');
}
void tx_driveRight() {
//Serial.write('F');
Serial1.write('f');
}
void rx_driveRight() {
Serial.write('F');
//Serial1.write('f');
}
void tx_releaseDriveRight() {
//Serial.write('U');
Serial1.write('u');
}
void rx_releaseDriveRight() {
Serial.write('U');
//Serial1.write('u');
}
void tx_clampClose() {
//Serial.write('G');
Serial2.write('g');
}
void rx_clampClose() {
Serial.write('G');
//Serial1.write('g');
}
void tx_releaseClampClose() {
//Serial.write('T');
Serial2.write('t');
}
void rx_releaseClampClose() {
Serial.write('T');
//Serial1.write('t');
}
void tx_clampOpen() {
//Serial.write('H');
Serial2.write('h');
}
void rx_clampOpen() {
Serial.write('H');
//Serial1.write('h');
}
void tx_releaseClampOpen() {
//Serial.write('S');
Serial2.write('s');
}
void rx_releaseClampOpen() {
Serial.write('S');
//Serial1.write('s');
}
void tx_lightsOn() {
//Serial.write('I');
Serial2.write('i');
}
void rx_lightsOn() {
Serial.write('I');
//Serial1.write('i');
}
void tx_releaseLightsOn() {
//Serial.write('R');
Serial2.write('r');
}
void rx_releaseLightsOn() {
Serial.write('R');
//Serial1.write('r');
}
void tx_lightsOff() {
//Serial.write('J');
Serial2.write('j');
}
void rx_lightsOff() {
Serial.write('J');
//Serial1.write('j');
}
void tx_releaseLightsOff() {
//Serial.write('Q');
Serial2.write('q');
}
void rx_releaseLightsOff() {
Serial.write('Q');
//Serial1.write('q');
}
//countinuously watches the recieved serial char for appropriate cases and runs the appropriate function
void loop() {
char incomingChar = 0; // for incoming serial data
if (Serial.available() > 0) {
incomingChar = Serial.read();
switch (incomingChar) {
//-----------------------------ROV Submersible Drive Up/Down
case 'a':
tx_driveUp();
break;
case 'z': //ROV Submersible Stop Driving Up/Down
tx_releaseDriveUp();
break;
case 'b':
tx_driveDown();
break;
case 'y': //ROV Submersible Stop Driving Up/Down
tx_releaseDriveDown();
break;
//-----------------------------ROV Submersible Drive Forward/Backward
case 'c':
tx_driveForward();
break;
case 'x': //ROV Submersible Stop Driving Forward
tx_releaseDriveForward();
break;
case 'd':
tx_driveBackward();
break;
case 'w': //ROV Submersible Stop Driving Backward
tx_releaseDriveBackward();
break;
//-----------------------------ROV Submersible Drive Left/Right
case 'e':
tx_driveLeft();
break;
case 'v': //ROV Submersible Stop Driving Left
tx_releaseDriveLeft();
break;
case 'f':
tx_driveRight();
break;
case 'u': //ROV Submersible Stop Driving Right
tx_releaseDriveRight();
break;
//-----------------------------ROV Submersible Clamp Open/Close
case 'g':
tx_clampClose();
break;
case 't': //ROV Submersible Clamp Stop OClosing
tx_releaseClampClose();
break;
case 'h':
tx_clampOpen();
break;
case 's': //ROV Submersible Clamp Stop Opening
tx_releaseClampOpen();
break;
//-----------------------------ROV Submersible Lights On/Off
case 'i':
tx_lightsOn();
break;
case 'r': //ROV Submersible Lights Stop On
tx_releaseLightsOn();
break;
case 'j':
tx_lightsOff();
break;
case 'q': //ROV Submersible Lights Stop Off
tx_releaseLightsOff();
break;
default:
Serial.write('N'); // BLACK
break;
}
/* not really needed but in case you want to do things in the loop forwardon receiving new chars. if (incomingChar == 0) then no new char was received,
otherwise later in the loop you still have the char received*/
} else incomingChar = 0;
if (Serial1.available() > 0) {
incomingChar = Serial1.read();
switch (incomingChar) {
//-----------------------------ROV Submersible Drive Up/Down
case 'A':
rx_driveUp();
break;
case 'Z': //ROV Submersible Stop Driving Up/Down
rx_releaseDriveUp();
break;
case 'B':
rx_driveDown();
break;
case 'Y': //ROV Submersible Stop Driving Up/Down
rx_releaseDriveDown();
break;
//-----------------------------ROV Submersible Drive Forward/Backward
case 'C':
rx_driveForward();
break;
case 'X': //ROV Submersible Stop Driving Forward
rx_releaseDriveForward();
break;
case 'D':
rx_driveBackward();
break;
case 'W': //ROV Submersible Stop Driving Backward
rx_releaseDriveBackward();
break;
//-----------------------------ROV Submersible Drive Left/Right
case 'E':
rx_driveLeft();
break;
case 'V': //ROV Submersible Stop Driving Left
rx_releaseDriveLeft();
break;
case 'F':
rx_driveRight();
break;
case 'U': //ROV Submersible Stop Driving Right
rx_releaseDriveRight();
break;
//-----------------------------ROV Submersible Clamp Open/Close
/* case 'G':
rx_clampClose();
break;
case 'T': //ROV Submersible Clamp Stop OClosing
rx_releaseClampClose();
break;
case 'H':
rx_clampOpen();
break;
case 'S': //ROV Submersible Clamp Stop Opening
rx_releaseClampOpen();
break;
//-----------------------------ROV Submersible Lights On/Off
case 'I':
rx_lightsOn();
break;
case 'R': //ROV Submersible Lights Stop On
rx_releaseLightsOn();
break;
case 'J':
rx_lightsOff();
break;
case 'Q': //ROV Submersible Lights Stop Off
rx_releaseLightsOff();
break;
default:
Serial.write('N'); // BLACK
break;
*/
}
/* not really needed but in case you want to do things in the loop forwardon receiving new chars. if (incomingChar == 0) then no new char was received,
otherwise later in the loop you still have the char received*/
} else incomingChar = 0;
if (Serial2.available() > 0) {
incomingChar = Serial2.read();
switch (incomingChar) {
/*
//-----------------------------ROV Submersible Drive Up/Down
case 'A':
rx_driveUp();
break;
case 'Z': //ROV Submersible Stop Driving Up/Down
rx_releaseDriveUp();
break;
case 'B':
rx_driveDown();
break;
case 'Y': //ROV Submersible Stop Driving Up/Down
rx_releaseDriveDown();
break;
//-----------------------------ROV Submersible Drive Forward/Backward
case 'C':
rx_driveForward();
break;
case 'X': //ROV Submersible Stop Driving Forward
rx_releaseDriveForward();
break;
case 'D':
rx_driveBackward();
break;
case 'W': //ROV Submersible Stop Driving Backward
rx_releaseDriveBackward();
break;
//-----------------------------ROV Submersible Drive Left/Right
case 'E':
rx_driveLeft();
break;
case 'V': //ROV Submersible Stop Driving Left
rx_releaseDriveLeft();
break;
case 'F':
rx_driveRight();
break;
case 'U': //ROV Submersible Stop Driving Right
rx_releaseDriveRight();
break;
*/
//-----------------------------ROV Submersible Clamp Open/Close
case 'G':
rx_clampClose();
break;
case 'T': //ROV Submersible Clamp Stop OClosing
rx_releaseClampClose();
break;
case 'H':
rx_clampOpen();
break;
case 'S': //ROV Submersible Clamp Stop Opening
rx_releaseClampOpen();
break;
//-----------------------------ROV Submersible Lights On/Off
case 'I':
rx_lightsOn();
break;
case 'R': //ROV Submersible Lights Stop On
rx_releaseLightsOn();
break;
case 'J':
rx_lightsOff();
break;
case 'Q': //ROV Submersible Lights Stop Off
rx_releaseLightsOff();
break;
default:
Serial.write('N'); // BLACK
break;
}
/* not really needed but in case you want to do things in the loop forwardon receiving new chars. if (incomingChar == 0) then no new char was received,
otherwise later in the loop you still have the char received*/
} else incomingChar = 0;
}
Sketch for the Uno (currently mirrored on both Uno)
void setup() {
Serial.begin(9600); // enables the serial connection. Make sure it's the same on both sides (here in the Arduino IDE and in the Processing program)
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
//Char sent to the processing program via usb serial to visulise transmit/recieve
void driveUp() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
Serial.write('A');
}
void releaseDriveUp() {
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
Serial.write('Z');
}
void driveDown() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
Serial.write('B');
}
void releaseDriveDown() {
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
Serial.write('Y');
}
void driveForward() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
Serial.write('C');
}
void releaseDriveForward() {
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
Serial.write('X');
}
void driveBackward() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
Serial.write('D');
}
void releaseDriveBackward() {
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
Serial.write('W');
}
void driveLeft() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
Serial.write('E');
}
void releaseDriveLeft() {
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
Serial.write('V');
}
void driveRight() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
Serial.write('F');
}
void releaseDriveRight() {
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
Serial.write('U');
}
void clampClose() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
Serial.write('G');
}
void releaseClampClose() {
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
Serial.write('T');
}
void clampOpen() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
Serial.write('H');
}
void releaseClampOpen() {
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
Serial.write('S');
}
void lightsOn() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
Serial.write('I');
}
void releaseLightsOn() {
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
Serial.write('R');
}
void lightsOff() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
Serial.write('J');
}
void releaseLightsOff() {
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
Serial.write('Q');
}
//countinuously watches the recieved serial char for appropriate cases and runs the appropriate function
void loop() {
char incomingChar = 0; // for incoming serial data
if (Serial.available() > 0) {
incomingChar = Serial.read();
switch (incomingChar) {
//-----------------------------ROV Submersible Drive Up/Down
case 'a':
driveUp();
break;
case 'z': //ROV Submersible Stop Driving Up/Down
releaseDriveUp();
break;
case 'b':
driveDown();
break;
case 'y': //ROV Submersible Stop Driving Up/Down
releaseDriveDown();
break;
//-----------------------------ROV Submersible Drive Forward/Backward
case 'c':
driveForward();
break;
case 'x': //ROV Submersible Stop Driving Forward
releaseDriveForward();
break;
case 'd':
driveBackward();
break;
case 'w': //ROV Submersible Stop Driving Backward
releaseDriveBackward();
break;
//-----------------------------ROV Submersible Drive Left/Right
case 'e':
driveLeft();
break;
case 'v': //ROV Submersible Stop Driving Left
releaseDriveLeft();
break;
case 'f':
driveRight();
break;
case 'u': //ROV Submersible Stop Driving Right
releaseDriveRight();
break;
//-----------------------------ROV Submersible Clamp Open/Close
case 'g':
clampClose();
break;
case 't': //ROV Submersible Clamp Stop OClosing
releaseClampClose();
break;
case 'h':
clampOpen();
break;
case 's': //ROV Submersible Clamp Stop Opening
releaseClampOpen();
break;
//-----------------------------ROV Submersible Lights On/Off
case 'i':
lightsOn();
break;
case 'r': //ROV Submersible Lights Stop On
releaseLightsOn();
break;
case 'j':
lightsOff();
break;
case 'q': //ROV Submersible Lights Stop Off
releaseLightsOff();
break;
default:
Serial.write('N'); // BLACK
break;
}
/* not really needed but in case you want to do things in the loop forwardon receiving new chars. if (incomingChar == 0) then no new char was received,
otherwise later in the loop you still have the char received*/
} else incomingChar = 0;
}
Processing Code
import processing.serial.*;
// The serial port:
Serial mySerialPort;
color fillVal = color(0); //sets up initial colour for program window - black/blank
//setting a condition on a keypress to eliminate the continued press of a key when holding a button
boolean driveUp = false;
boolean driveDown = false;
boolean driveForward = false;
boolean driveBackward = false;
boolean driveLeft = false;
boolean driveRight = false;
boolean clampClose = false;
boolean clampOpen = false;
boolean lightsOn = false;
boolean lightsOff = false;
String year, month, day, hour, minute, second, millis;
float txCharCount = 0;
float rxCharCount = 1; //- off set to zero the serial count
void setup() {
size(100, 100);//program indication window size
noStroke();
background(255);
printArray(Serial.list()); // do this to find your arduino
// Open the port you are using at the rate you want:
mySerialPort = new Serial(this, Serial.list()[2], 9600);// this port 2 should correspond to the com port the arduino is plugged into - example: 2 = COM6
mySerialPort.clear();
}
void draw() {
background(fillVal);//sets window background colour
}
void keyPressed() {
//Setting timestamp format
year = nf(year(), 4);
month = nf(month(), 2);
day = nf(day(), 2);
hour = nf(hour(), 2);
minute = nf(minute(), 2);
second = nf(second(), 2);
millis = nf(millis(), 4);
//ROV Submersible Drive Up/Down
if (key == 'w' || key == 'W') {
if ( !driveUp) {
driveUp = true;
mySerialPort.write('a');
txCharCount ++;
println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+ " PC Transmit: 'a' - driveUp");
}
} else if (key == 's' || key == 'S') {
if ( !driveDown) {
driveDown = true;
mySerialPort.write('b');
txCharCount ++;
println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+ " PC Transmit: 'b' - driveDown");
}
}
//ROV Submersible Drive Forward/Backward
else if (keyCode == UP) {
if ( !driveForward) {
driveForward = true;
mySerialPort.write('c');
txCharCount ++;
println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+ " PC Transmit: 'c' - driveForward");
}
} else if (keyCode == DOWN) {
if ( !driveBackward) {
driveBackward = true;
mySerialPort.write('d');
txCharCount ++;
println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+ " PC Transmit: 'd' - driveBackward");
}
}
//ROV Submersible Drive Left/Right
else if (keyCode == LEFT) {
if ( !driveLeft) {
driveLeft = true;
mySerialPort.write('e');
txCharCount ++;
println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+ " PC Transmit: 'e' - driveLeft");
}
} else if (keyCode == RIGHT) {
if ( !driveRight) {
driveRight = true;
mySerialPort.write('f');
txCharCount ++;
println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+ " PC Transmit: 'f' - driveRight");
}
}
//ROV Submersible Clamp Open/Close
else if (key == 'd' || key == 'D') {
if ( !clampClose) {
clampClose = true;
mySerialPort.write('g');
txCharCount ++;
println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+ " PC Transmit: 'g' - clampClose");
}
} else if (key == 'a' || key == 'A') {
if ( !clampOpen) {
clampOpen = true;
mySerialPort.write('h');
txCharCount ++;
println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+ " PC Transmit: 'h' - clampOpen");
}
}
//ROV Submersible Lights On/Off
else if (key == 'e' || key == 'E') {
if ( !lightsOn) {
lightsOn = true;
mySerialPort.write('i');
txCharCount ++;
println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+ " PC Transmit: 'i' - lightsOn");
}
} else if (key == 'q' || key == 'Q') {
if ( !lightsOff) {
lightsOff = true;
mySerialPort.write('j');
txCharCount ++;
println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+ " PC Transmit: 'j' - lightsOff");
}
}
float reliability = rxCharCount/txCharCount*100;
println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+" Communications - "+txCharCount+" tx"+" : "+rxCharCount+" rx " + nf(reliability, 2, 1)+ "% ");
}
//The keyReleased() function is called once every time a key is released. This essentially resets the motors being controlled by the arduino stopping them from spinning - the b char that is sent releases the motors from use
void keyReleased() {
//Setting timestamp format
year = nf(year(), 4);
month = nf(month(), 2);
day = nf(day(), 2);
hour = nf(hour(), 2);
minute = nf(minute(), 2);
second = nf(second(), 2);
millis = nf(millis(), 4);
//ROV Submersible Stop Going Up/Down
if (key == 'w' || key == 'W') {
driveUp = false;
mySerialPort.write('z');
//txCharCount ++;
//println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+ " PC Transmit: 'z' - stop driveUp");
} else if (key == 's' || key == 'S') {
driveDown = false;
mySerialPort.write('y');
//txCharCount ++;
//println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+ " PC Transmit: 'y' - stop driveDown");
}
//ROV Submersible Stop Driving Forward/Backward
else if (keyCode == UP) {
driveForward = false;
mySerialPort.write('x');
//txCharCount ++;
//println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+ " PC Transmit: 'x' - stop driveForward");
} else if (keyCode == DOWN) {
driveBackward = false;
mySerialPort.write('w');
//txCharCount ++;
//println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+ " PC Transmit: 'w' - stop driveBackward");
}
//ROV Submersible Stop Driving Left/Right
else if (keyCode == LEFT) {
driveLeft = false;
mySerialPort.write('v');
//txCharCount ++;
//println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+ " PC Transmit: 'v' - stop driveLeft");
} else if (keyCode == RIGHT) {
driveRight = false;
mySerialPort.write('u');
//txCharCount ++;
//println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+ " PC Transmit: 'u' - stop driveRight");
}
//ROV Submersible Clamp Stop Opening/Closing
else if (key == 'd' || key == 'D') {
clampClose = false;
mySerialPort.write('t');
//txCharCount ++;
//println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+ " PC Transmit: 't' - stop clampClose");
} else if (key == 'a' || key == 'A') {
clampOpen = false;
mySerialPort.write('s');
//txCharCount ++;
//println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+ " PC Transmit: 's' - stop clampOpen");
}
//ROV Submersible Lights Stop On/Off
else if (key == 'e' || key == 'E') {
lightsOn = false;
mySerialPort.write('r');
//txCharCount ++;
//println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+ " PC Transmit: 'r' - stop lightsOn");
} else if (key == 'q' || key == 'Q') {
lightsOff = false;
mySerialPort.write('q');
//txCharCount ++;
//println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+ " PC Transmit: 'q' - stop lightsOff");
}
}
//assigns the background colours of the program window
void serialEvent(Serial p) {
//Setting timestamp format
year = nf(year(), 4);
month = nf(month(), 2);
day = nf(day(), 2);
hour = nf(hour(), 2);
minute = nf(minute(), 2);
second = nf(second(), 2);
millis = nf(millis(), 4);
switch(p.read()) {
case 'A':
fillVal = #FF416C;//Vibrant Red - Drive Up
rxCharCount++;
println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+" ROV Receive: 'A' - driveUp");
break;
case 'B':
fillVal = #F9C74F;//Vibrant Yellow - Drive Down
rxCharCount++;
println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+" ROV Receive: 'B' - driveDown");
break;
case 'C':
fillVal = #0077B6;//Vibrant Blue - Drive Forward
rxCharCount++;
println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+" ROV Receive: 'C' - driveForward");
break;
case 'D':
fillVal = #2AA877;//Vibrant Green - Drive Backward
rxCharCount++;
println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+" ROV Receive: 'D' - driveDown");
break;
case 'E':
fillVal = #FF6F00;//Vibrant Orange - Drive Left
rxCharCount++;
println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+" ROV Receive: 'E' - driveLeft");
break;
case 'F':
fillVal = #7A3B69;//Vibrant Purple - Drive Right
rxCharCount++;
println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+" ROV Receive: 'F' - driveRight");
break;
case 'G':
fillVal = #00A7B5;//Vibrant Teal - Clamp Close
rxCharCount++;
println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+" ROV Receive: 'G' - clampClose");
break;
case 'H':
fillVal = #FF66A1;//Vibrant Pink - Clamp Open
rxCharCount++;
println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+" ROV Receive: 'H' - clampOpen");
break;
case 'I':
fillVal = #C2E812;//Vibrant Lime Green - Lights On
rxCharCount++;
println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+" ROV Receive: 'I' - lightsOn");
break;
case 'J':
fillVal = #00C2B1;//Vibrant Turquoise - Lights Off
rxCharCount++;
println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+" ROV Receive: 'J' - lightsOff");
break;
/*-------------------------------------------------------------------------------------------------------------------*/
/* case 'Q':
//fillVal = #FF416C;//Vibrant Red - Drive Up
rxCharCount++;
//println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+ " ROV Receive: 'Q' - releaseLightsOff");
break;
case 'R':
//fillVal = #F9C74F;//Vibrant Yellow - Drive Down
rxCharCount++;
//println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+ " ROV Receive: 'R' - releaseLightsOn");
break;
case 'S':
//fillVal = #0077B6;//Vibrant Blue - Drive Forward
rxCharCount++;
//println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+ " ROV Receive: 'S' - releaseClampOpen");
break;
case 'T':
//fillVal = #2AA877;//Vibrant Green - Drive Backward
rxCharCount++;
//println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+ " ROV Receive: 'T' - releaseClampClose");
break;
case 'U':
//fillVal = #FF6F00;//Vibrant Orange - Drive Left
rxCharCount++;
//println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+ " ROV Receive: 'U' - releaseDriveRight");
break;
case 'V':
//fillVal = #7A3B69;//Vibrant Purple - Drive Right
rxCharCount++;
//println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+ " ROV Receive: 'V' - releaseDriveLeft");
break;
case 'W':
//fillVal = #00A7B5;//Vibrant Teal - Clamp Close
rxCharCount++;
//println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+ " ROV Receive: 'W' - releaseDriveDown");
break;
case 'X':
//fillVal = #FF66A1;//Vibrant Pink - Clamp Open
rxCharCount++;
//println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+ " ROV Receive: 'X' - releaseDriveForward");
break;
case 'Y':
//fillVal = #C2E812;//Vibrant Lime Green - Lights On
rxCharCount++;
//println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+ " ROV Receive: 'Y' - releaseDriveDown");
break;
case 'Z':
//fillVal = #00C2B1;//Vibrant Turquoise - Lights Off
rxCharCount++;
//println(year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second+"."+millis+ " ROV Receive: 'Z' - releaseDriveUp");
break;
*/
default:
fillVal = #000000;//Black
break;
}
}
Extra question for anyone in the Processing 'know': I seem to have hit a limit with the Case switch for my char. I didnt notice loss of char however when the case breaks out it should call the default case and fill the background black - when I include another 5+ char Cases - similarly to what is commented out. the default is not called and the background stays the colour of the last keypress