09-30-2019 04:46 AM - edited 09-30-2019 05:00 AM
Dear all,
I am trying to send serial commands to Arduino using Labview for controlling two LEDs. Led1 should either on or off and Led2 will blink in both states of Led1. The state of led1 and duty cycle of led2(using delay function) are sent to Arduino by LabVIEW. Later I have to use this code for running a motor but to test it I am using LEDs.Code I have written for this operation is attached with this mail. this code works properly for a couple of minutes and then stops working. Reason for it I can think of are
1. The difference between the size of concatenated strings(delay get more character than deciding the state of led1)
2. Another one is Arduino and LabVIEW timings are not synchronized.
or
I don't know what's happening as I'm new to interfacing it seems daunting for me to find the right direction. But as I go for highlight execution program works totally fine so I can conclude that there is timing problem somewhere. If anyone who can help me sort it out I will be really grateful for the efforts.
Thanks
Arduino code
#define Pulse 4
#define Dir 3
char data;
char number;
int p;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(Pulse, OUTPUT);
pinMode(Dir, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int p;
if(Serial.available())
{
String number = Serial.readStringUntil('&');
p = number.toInt();
Serial.print(p);
data = Serial.read();
if(data == 'H')
{digitalWrite(Dir, HIGH);
digitalWrite(Pulse, HIGH);
delay(p);
digitalWrite(Pulse, LOW);
delay(p);
}
else if(data == 'L')
{digitalWrite(Dir, LOW);
digitalWrite(Pulse, HIGH);
delay(p);
digitalWrite(Pulse, LOW);
delay(p);
}
else{}
}
}