Sorry I'm from the videogame industry, I might not use the proper terms.
Anyway, here is why I can't change it (or maybe I'm missing something) :
ServoControl.cpp => Calls the SerialCom
From a loop, The servo goes from 0 to 180 then from 180 to 0. Works as intended ![]()
//When called, move the servo from a position to another
void ServoControlClass::MoveServo(bool stop_i)
{
stop_o=stop_i;
if(!stop_o)
{
if(currentPos==0)
{
delay(2000);
moving_o=1;
SerialComClass.PushData(ServoControl_cls.moving_o);
servo1.write(180);
servo2.write(180);
currentPos=180;
delay(2000);
moving_o=0;
SerialComClass.PushData(ServoControl_cls.moving_o);
}
if(currentPos==180)
{
delay(2000);
moving_o=1;
SerialComClass.PushData(ServoControl_cls.moving_o);
servo1.write(0);
servo2.write(0);
currentPos=0;
delay(2000);
moving_o=0;
SerialComClass.PushData(ServoControl_cls.moving_o);
}
}
else
{
servo1.write(0);
servo2.write(0);
}
}
SerialCom
Called by the servoClass. Send true or false. Works as intended ![]()
//Initialize the communication between the 2Cards
void SerialComClass::InitCom()
{
softSerial.begin(9600);
softSerial.setTimeout(100);
Serial.print("Test");
softSerial.println("Hello, world?");
pinMode(12,INPUT);
pinMode(13,OUTPUT);
}
///Push/Transmit Data to the D1Mini
void SerialComClass::PushData(int moveState)
{
if(moveState){
softSerial.print("true-");
}
else{
softSerial.print("false-");
}
Serial.println("Sending " + (String)moveState);
}
Serial monitor from arduino
13:29:58.454 -> Sending 1
13:30:00.474 -> Sending 0
13:30:02.479 -> Sending 1
13:30:04.496 -> Sending 0
13:30:06.500 -> Sending 1
13:30:08.510 -> Sending 0
13:30:10.516 -> Sending 1
D1mini Side
GetNewData() is called by a loop
void ReadData() is called by a loop
void loop() {
// put your main code here, to run repeatedly:
//Get New InputData();
GetNewData();
//Send new data
ReadData();
}
void GetNewData()
{
while(softSerial.available()>0)
{
valStr=softSerial.readStringUntil('-');
newData=true;
}
}
//Read datas
void ReadData()
{
Serial.println("receive "+valStr);
if(valInt==0)
{
valBool=false;
}
if(valInt==1)
{
valBool=true;
}
newData=false;
}
Serial Monitor from D1Mini
13:31:05.446 -> receive false
13:31:09.613 -> receive false
13:31:13.320 -> receive false
13:31:17.009 -> receive false
13:31:20.769 -> receive false
13:31:24.404 -> receive true
13:31:28.183 -> receive true
13:31:31.943 -> receive true