Hoping someone can help me.
I have two Arduino Megas connected via serial 1.
Mega Board 1 collects sensor data and outputs it on serial1. I have no problems here.
Mega Board 2 reads the serial data from Mega Board 1 and displays the data. This is where I am having trouble.
(Note: There is a reason I'm using two boards but I've stripped my code down to the bare minimum here for troubleshooting and am using the serial monitor on the second board simply to see if the code is working.)
Here is the issue:
Anytime I use the line "SensorVel = Serial1.parseFloat();" the button effectively fails to switch the cases. I say effectively because if I push the button many times, occasionally the display board with switch cases for me.
If I comment out the Serial1.parseFloat(), the program runs great switching between cases.
The other interesting (aka "frustrating") thing I notice is that when the serial data is displayed, the program seems to slow down quite a bit. I don't know if this is unavoidable due to the time required to read the serial data or if there is anything else I can do. The serial data is just a stream of integers.
Can anyone advise me why the program effectively stops responding to the button being switched anytime I use the Serial1.parseFloat() command and how to solve the problem.
I'm very new to programming the Arduino and to this forum, so please excuse me for any oversights.
Here is the test code:
#define button 22
#define relay 34
int SensorVel = 0;
int DisplaySpeed = 0;
int state = 0;
int old = 0;
int buttonPoll = 0;
int DisplayPwr = 0;
void setup() {
Serial.begin(19200);
Serial1.begin(19200);
pinMode (button, INPUT);
pinMode (relay, OUTPUT);
digitalWrite(relay,HIGH);
}
void loop() {
// MONITOR BUTTON PUSHED TO SELECT MODE
buttonPoll = digitalRead(button);
if(buttonPoll == 1){
delay(50);
buttonPoll = digitalRead(button);
if(buttonPoll == 0){
state = old + 1;
}}
else{
delay(100);
}
// SPECIFY WHAT MODE IS USED
switch (state) {
case 1:
DisplaySpeed = 0;
SensorVel = Serial1.parseFloat();
Serial.print("Case 1: ");
Serial.println(SensorVel);
old = state;
break;
case 2:
DisplaySpeed = 0;
// SensorVel = Serial1.parseFloat();
Serial.print("Case 2: ");
Serial.println(SensorVel);
old = state;
break;
default:
digitalWrite(relay,LOW);
Serial.println("Case 3: ");
old = 0;
break;
}
}