Good day,
I am trying to work with C#, Arduino and a LED power supply. First, C# will send some code sequence to my Arduino to activate my motor. I use encoder on the motor to know its position. When my desired position is reached by the motor, C# will send another sequence to my LED power supply. How to make it work? Now when I send my code, C# will send sequence to my LED power supply when my desired position isn't reached yet. I hope someone can help me. Thank you.
C# code:
arduino.write("A175");
if(arduino.read=="G") {
powersuppy.write("S100T000F000F000FC#");
} else { }
Arduino Code:
if(serial.Available()>0) {
data=Serial.read();
if (data=='A') {
int destination=parseInt(Serial.read());
for(count; count<destination ;count++) {
motorgo();
encoder();
}
Serial.write("G");
}
}
You are sending "G" to the C# after the for-loop ends. You need to check if position is reached THEN send "G".