Hi everyone,
I have a question about SoftwareSerial,
I can not make my code work, I tried everything that I know, but still I have not managed to get my code to work, I think the problem with the code will be very simple, but I can not decipher it, I'll add my code, who can help me?
that is my code:
#include <SoftwareSerial.h>
SoftwareSerial portOne(16, 10);
SoftwareSerial portTwo(14, 15); // RX, TX
const int BTest = 3;
const int LedOn = 9;
const int LedP = 8;
bool estadoActual = false, estadoUltimo = false, contador = false;
char a, b;
void setup()
{
Serial.begin(9600);
portOne.begin(9600);
portTwo.begin(9600);
pinMode(BTest, INPUT);
pinMode(LedOn, OUTPUT);
pinMode(LedP, OUTPUT);
}
void loop()
{
estadoActual = digitalRead(BTest);
delay(50);
if (estadoActual && !estadoUltimo)
{
contador = !contador;
if (contador)
{
Serial.println("ON");
Serial.println(contador);
portOne.listen();
portOne.print("2");
digitalWrite(LedP, HIGH);
a = portOne.read();
if (a == '1')
{
digitalWrite(LedOn, LOW);
}
}
else
{
Serial.println("OFF");
Serial.println(contador);
portTwo.listen();
portTwo.print("1");
digitalWrite(LedP, LOW);
b = portTwo.read();
if (b == '2')
{
digitalWrite(LedOn, HIGH);
}
}
}
estadoUltimo = estadoActual;
}
In the arduino connections, I connected 15Tx (portTwo) with 16Rx (portOne) and 10Tx (portOne) with 14Rx (portTwo).
I am using an arduino Pro Micro.
thanks and regards.