代码拉取完成,页面将自动刷新
#include <Stepper.h>
const int stepsPerRevolution = 2048;
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
int countab = 0;
int a = 999999, b = 0;
unsigned long count_low, buttonDelay = 1000;
void setup()
{
myStepper.setSpeed(5);
Serial.begin(9600);
attachInterrupt(0, handler_falling, FALLING); // pin2
attachInterrupt(0, handler_low, LOW);
attachInterrupt(0, handler_rising, RISING);
}
void loop()
{
if (Serial.available() > 0)
{
int c = Serial.read();
if (c == 1)
{
while (1)
{
if (analogRead(A0) >= a)
break;
myStepper.step(32);
}
}
else if (c == 2)
{
while (1)
{
if (analogRead(A0) <= b)
break;
myStepper.step(-32);
}
}
}
}
void handler_falling()
{
if (countab == 0)
{
a = analogRead(A0);
countab++;
}
else if (countab == 1)
{
b = analogRead(A0);
countab = 0;
}
}
void handler_low()
{
count_low = millis();
}
void handler_rising()
{
if (millis() - count_low >= buttonDelay)
{
a = 999999;
b = 0;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。