I have been working on a project where the following steps have to be carried out.
Receive data on the Bluetooth device onto Arduino mega. (DONE)
Compute the data and according to the output make if-else statements. (DONE)
The if-else statements has a particular character to be send to ARDUINO LEONARDO if the condition is true.
Receive the character from Arduino Mega onto Arduino Leonardo and do further actions on Leonardo.
Now I have already completed the first 2 steps but was unable to make the Arduino's communicate. I have to send only 1 character and not a string. The RX0 and TX0 on the Mega have already been used, so either I have to use SoftwareSerial or any other RX/TX.
I have not yet connected the Leonardo to the Mega. Can you guide me how can I connect them both? I already have the Serial port 0 of Mega connected to Bluetooth. So RX0/TX0 are already used. I need to use the serial ports 1-3 to communicate. It would be of great help if you can help me.
Thank you in advance.
I need to use the serial ports 1-3 to communicate.
So, what is the problem? The RXn and TXn pins are clearly called out on the Mega. The n in the name corresponds to the n in the Serialn instance to use.
Why is there no Serial1.begin()? What is connected to the Serial instance(s) on the Lenny?
Arduino Mega Code
Which hasn't a hope in hell of compiling. Come on back when you have something that does.
Serial.println(brain.readCSV());
This is absolutely pointless. You have the hardware connected to the main hardware serial instance. You can NOT use that instance to debug your code, too.
On the lenny I have connected the Mega's TX1(pin 18) to it's RX pin.
The Leonardo's RX and TX pins are connected to its Serial1 instance, not its Serial instance.
if (0 <brain.readAttention() < 25)
Compare 0 to the value returned by the readAttention() method. The result is either true (1) or false (0). the last time I checked, both true and false are less than 25, so this statement will always be true.
if (26 < brain.readAttention() < 50)
True and false are less than 50, too. So, this statement will always be true.
if (76 < brain.readAttention() < 100)
And this one.
Why was it necessary to call the readAttention() method three times?