Hi,
I am using two Arduino Mega's:
Master - This gets it's orders from bluetooth (something like e,f,g... or 1,2,3...). What I want is each case is some letter or number. And and each case sends another letter or number to the Arduino Slave.
Slave - This gets it's orders from Arduino Master over serial (something like a,b,c... or 5,6,7...). And when the right letter or number is received, it does it's case.
This is Arduino Slave short test code without seral.read, because I don't know how to make a working one:
int Button1 = 43;
int Button2 = 45;
int DC1 = 10;
int DC2 = 11;
void setup()
{
pinMode(Button1, INPUT_PULLUP);
pinMode(Button2, INPUT_PULLUP);
pinMode(DC1,OUTPUT);
pinMode(DC2,OUTPUT);
Serial.begin(9600);
}
void loop()
{
switch(state)
{
case 0:
break;
case 1:
if ------------------------ This is where I want something like "serial.read receives letter a"
{
Serial.print("DC left");
digitalWrite(DC1, LOW);
digitalWrite(DC2, HIGH);
}
else if(digitalRead(Button1) == HIGH)
{
Serial.print("DC left stop");
digitalWrite(DC1, LOW);
digitalWrite(DC2, LOW);
state = 0;
}
break;
case 2:
if ------------------------ This is where I want something like "serial.read receives letter b"
{
Serial.print("DC right");
digitalWrite(DC1, HIGH);
digitalWrite(DC2, LOW);
}
else if(digitalRead(Button1) == HIGH)
{
Serial.print("DC right stop");
digitalWrite(DC1, LOW);
digitalWrite(DC2, LOW);
state = 0;
}
break;
default:
state = 0;
break;
}
}
Arduino Master code is similar. But there will be sensors over analogRead and Wire library. Some Nema steppers and relays.
I think Finite State Machine like code is way to go. I know I can't use strings. And I think I'm overthinking or missing something I have tried many thing, but they don't work together. Can It be done in this way, and how?
Sorry for any mistakes. English is not my native language