代码无法编译,在','令牌错误之前给出了预期的primary-expression。我想这是明显的,但我找不到它 感谢名单
这是应该运行一些步进电机的代码 问题显示在最后一行说“预期的'在'之前','令牌' 好吧,我也想知道它是什么类型的错误,所以我可以在将来解决这个问题
/*
*
*/
//step
#define step_1 14
#define step_2 27
//direction
#define dir_1 12
#define dir_2 13
//buttons
#define go_1
#define go_2
#define go_3
#define go_4
//enable
#define enbl_1
#define enbl_2
//settings
#define rpms 100.0
#define steps_per_rev 100
#define m_per_s 1 /*microsteps per second */
#define m_per_m (1000000/(steps_per_rev * m_per_s)/(rpms / 60)) /* microseconds per microstep */
uint32_t last_step_time = 0;
uint32_t current_time = 0;
boolean stepping_1 = false;
boolean stepping_2 = false;
void setup() {
//step
pinMode(step_1, OUTPUT);
pinMode(step_2, OUTPUT);
digitalWrite(step_1, LOW);
digitalWrite(step_2, LOW);
//dir
pinMode(dir_1, OUTPUT);
pinMode(dir_2, OUTPUT);
digitalWrite(dir_1, LOW);
digitalWrite(dir_2, LOW);
//enbl
pinMode(enbl_1, INPUT);
pinMode(enbl_2, INPUT);
digitalWrite(enbl_1, HIGH);
digitalWrite(enbl_2, HIGH);
//go
pinMode(go_1, INPUT);
pinMode(go_2, INPUT);
pinMode(go_3, INPUT);
pinMode(go_4, INPUT);
}
void loop() {
stepping_1 = true;
if (digitalRead(go_1) == LOW && stepping_1 == true)
{
current_time = micros(); // returns the time gone from the moment when the program has been runned
if ((current_time - last_step_time) > m_per_m)
{
digitalWrite(enbl_1, LOW);
digitalWrite(dir_1, LOW);
last_step_time = current_time;
digitalWrite(step_1, HIGH);
delayMicroseconds((m_per_m * 0.9)/2);
digitalWrite(step_1, LOW);
delayMicroseconds((m_per_m * 0.9)/2);
digitalWrite(enbl_1, HIGH);
}
}
if (digitalRead(go_2) == LOW && stepping_1 == true)
{
current_time = micros(); // returns the time gone from the moment when the program has been runned
if ((current_time - last_step_time) > m_per_m)
{
digitalWrite(enbl_1, LOW);
digitalWrite(dir_1, HIGH);
last_step_time = current_time;
digitalWrite(step_1, HIGH);
delayMicroseconds((m_per_m * 0.9)/2);
digitalWrite(step_1, LOW);
delayMicroseconds((m_per_m * 0.9)/2);
digitalWrite(enbl_1, HIGH);
}
}
if (digitalRead(go_3) == LOW && stepping_1 == true)
{
current_time = micros(); // returns the time gone from the moment when the program has been runned
if ((current_time - last_step_time) > m_per_m)
{
digitalWrite(enbl_2, LOW);
digitalWrite(dir_2, LOW);
last_step_time = current_time;
digitalWrite(step_2, HIGH);
delayMicroseconds((m_per_m * 0.9)/2);
digitalWrite(step_2, LOW);
delayMicroseconds((m_per_m * 0.9)/2);
digitalWrite(enbl_2, HIGH);
}
}
if (digitalRead(go_4) == LOW && stepping_1 == true)
{
current_time = micros(); // returns the time gone from the moment when the program has been runned
if ((current_time - last_step_time) > m_per_m)
{
digitalWrite(enbl_2, LOW);
digitalWrite(dir_2, HIGH);
last_step_time = current_time;
digitalWrite(step_2, HIGH);
delayMicroseconds((m_per_m * 0.9)/2);
digitalWrite(step_2, LOW);
delayMicroseconds((m_per_m * 0.9)/2);
digitalWrite(enbl_2, HIGH);
}
}
}
答案 0 :(得分:0)
#define
语句必须包含两个部分 - 别名/名称,以及它被定义为什么。如果您没有第二部分,则预处理器会将空白空间替换为您定义的名称。以下所有名称在您的程序中都未正确定义:
#define go_1
#define go_2
#define go_3
#define go_4
//enable
#define enbl_1
#define enbl_2
这导致预处理后pinMode(go_1, INPUT);
等行变为pinMode(, INPUT);
。
我还强烈建议您为定义使用全部大写,因为这将明确区分它们与实际变量。这很重要,因为定义的别名被替换为文字值,因此无法修改。