|
本人写了一个两个电机联动的程序,已经可以正常工作了,程序中红色字符串4到7位为修改速度的4位16进制,10到14是修改位移量的5位16进制,想通过labview通过上位机对这组字符串的速度和位移量 进行修改。不知怎么编写。请教一下大家。谢谢啦
#include <LiquidCrystal.h>
int PinA = 21;
long Pos = 0;
int rad = 0;
int Counter = 0;
int i = 0;
int a = 3;
unsigned long time = 0;
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup() {
Serial3.begin(9600);
lcd.begin(16, 2);
pinMode (PinA,INPUT);
attachInterrupt(2, blinkA, FALLING);
time = millis();
}
void loop() {
if (i == 0){
Serial3.print("0AR\r\n");
delay(2000);
Serial3.print("0MP00\r\n");
i = 1;
}
if ((millis() - time) > 1000){
Pos += Counter;
rad = Pos/1000;
lcd.clear();
lcd.print("Rotating speed:");
lcd.setCursor(0, 1);
lcd.print (rad);
time = millis();
Pos = 0;
}
if (Counter >= 1000){
if (rad < 20){
Serial3.print("0MV01903200003\r\n");//speed 400mm/s displacement 0.9mm
}
else {
Serial3.print("0MV00503200350\r\n");//speed 0mm/s displacement 25.44mm
}
Pos += Counter;
Counter = 0;
}
}
void blinkA() {
Counter ++;
}
|
|