Hello
I'm using arduino mega and i need to create some control system in Labview in real time.
I'm using a control and simulation loop and VISA to get a signal from arduino. My code in arduino:
volatile unsigned int counter = 0;
void setup() {
Serial.begin (9600);
pinMode(2, INPUT);
pinMode(3, INPUT);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
attachInterrupt(0, ai0, RISING);
attachInterrupt(1, ai1, RISING);
}
void loop() {
// Send the value of counter
Serial.println (counter);
delay(10);
}
void ai0() {
// ai0 is activated if DigitalPin nr 2 is going from LOW to HIGH
// Check pin 3 to determine the direction
if(digitalRead(3)==LOW) {
counter++;
}else{
counter--;
}
}
void ai1() {
// ai0 is activated if DigitalPin nr 3 is going from LOW to HIGH
// Check with pin 2 to determine the direction
if(digitalRead(2)==LOW) {
counter--;
}else{
counter++;
}
}
Then i made a sketch. But i can't understand how to get visa read signal and control simulation synchronously. I'm trying to vary delay() in arduino code but the precision is not good.