如何由电脑通过arduino控制步进电机
1个回答
展开全部
int val=0;
int i=0;
int Pin0 = 8;
int Pin1 = 9
;int Pin2 = 10;
int Pin3 = 11;
int step = 0;
int stepperSpeed = 1;
void setup()
{
pinMode(Pin0, OUTPUT);
pinMode(Pin1, OUTPUT);
pinMode(Pin2, OUTPUT);
pinMode(Pin3, OUTPUT);
Serial.begin(9600);
}
void loop()
{
val=Serial.read();
if (val=='a')
for(i=0;i<100;i++)
{
digitalWrite(Pin0, LOW); digitalWrite(Pin1, LOW); digitalWrite(Pin2, LOW); digitalWrite(Pin3, HIGH); delay(stepperSpeed);
digitalWrite(Pin0, LOW); digitalWrite(Pin1, LOW); digitalWrite(Pin2, HIGH); digitalWrite(Pin3, HIGH); delay(stepperSpeed);
digitalWrite(Pin0, LOW); digitalWrite(Pin1, LOW); digitalWrite(Pin2, HIGH); digitalWrite(Pin3, LOW); delay(stepperSpeed);
digitalWrite(Pin0, LOW); digitalWrite(Pin1, HIGH); digitalWrite(Pin2, HIGH); digitalWrite(Pin3, LOW); delay(stepperSpeed);
digitalWrite(Pin0, LOW); digitalWrite(Pin1, HIGH); digitalWrite(Pin2, LOW); digitalWrite(Pin3, LOW); delay(stepperSpeed);
digitalWrite(Pin0, HIGH); digitalWrite(Pin1, HIGH); digitalWrite(Pin2, LOW); digitalWrite(Pin3, LOW); delay(stepperSpeed);
digitalWrite(Pin0, HIGH); digitalWrite(Pin1, LOW); digitalWrite(Pin2, LOW); digitalWrite(Pin3, LOW); delay(stepperSpeed);
digitalWrite(Pin0, HIGH); digitalWrite(Pin1, LOW); digitalWrite(Pin2, LOW); digitalWrite(Pin3, HIGH); delay(stepperSpeed);
}
if (val=='b')
for(i=100;i>0;i--)
{
digitalWrite(Pin0, LOW); digitalWrite(Pin1, LOW); digitalWrite(Pin2, LOW); digitalWrite(Pin3, HIGH); delay(stepperSpeed);
digitalWrite(Pin0, LOW); digitalWrite(Pin1, LOW); digitalWrite(Pin2, HIGH); digitalWrite(Pin3, HIGH); delay(stepperSpeed);
digitalWrite(Pin0, LOW); digitalWrite(Pin1, LOW); digitalWrite(Pin2, HIGH); digitalWrite(Pin3, LOW); delay(stepperSpeed);
digitalWrite(Pin0, LOW); digitalWrite(Pin1, HIGH); digitalWrite(Pin2, HIGH); digitalWrite(Pin3, LOW); delay(stepperSpeed);
digitalWrite(Pin0, LOW); digitalWrite(Pin1, HIGH); digitalWrite(Pin2, LOW); digitalWrite(Pin3, LOW); delay(stepperSpeed);
digitalWrite(Pin0, HIGH); digitalWrite(Pin1, HIGH); digitalWrite(Pin2, LOW); digitalWrite(Pin3, LOW); delay(stepperSpeed);
digitalWrite(Pin0, HIGH); digitalWrite(Pin1, LOW); digitalWrite(Pin2, LOW); digitalWrite(Pin3, LOW); delay(stepperSpeed);
digitalWrite(Pin0, HIGH); digitalWrite(Pin1, LOW); digitalWrite(Pin2, LOW); digitalWrite(Pin3, HIGH); delay(stepperSpeed);
int i=0;
int Pin0 = 8;
int Pin1 = 9
;int Pin2 = 10;
int Pin3 = 11;
int step = 0;
int stepperSpeed = 1;
void setup()
{
pinMode(Pin0, OUTPUT);
pinMode(Pin1, OUTPUT);
pinMode(Pin2, OUTPUT);
pinMode(Pin3, OUTPUT);
Serial.begin(9600);
}
void loop()
{
val=Serial.read();
if (val=='a')
for(i=0;i<100;i++)
{
digitalWrite(Pin0, LOW); digitalWrite(Pin1, LOW); digitalWrite(Pin2, LOW); digitalWrite(Pin3, HIGH); delay(stepperSpeed);
digitalWrite(Pin0, LOW); digitalWrite(Pin1, LOW); digitalWrite(Pin2, HIGH); digitalWrite(Pin3, HIGH); delay(stepperSpeed);
digitalWrite(Pin0, LOW); digitalWrite(Pin1, LOW); digitalWrite(Pin2, HIGH); digitalWrite(Pin3, LOW); delay(stepperSpeed);
digitalWrite(Pin0, LOW); digitalWrite(Pin1, HIGH); digitalWrite(Pin2, HIGH); digitalWrite(Pin3, LOW); delay(stepperSpeed);
digitalWrite(Pin0, LOW); digitalWrite(Pin1, HIGH); digitalWrite(Pin2, LOW); digitalWrite(Pin3, LOW); delay(stepperSpeed);
digitalWrite(Pin0, HIGH); digitalWrite(Pin1, HIGH); digitalWrite(Pin2, LOW); digitalWrite(Pin3, LOW); delay(stepperSpeed);
digitalWrite(Pin0, HIGH); digitalWrite(Pin1, LOW); digitalWrite(Pin2, LOW); digitalWrite(Pin3, LOW); delay(stepperSpeed);
digitalWrite(Pin0, HIGH); digitalWrite(Pin1, LOW); digitalWrite(Pin2, LOW); digitalWrite(Pin3, HIGH); delay(stepperSpeed);
}
if (val=='b')
for(i=100;i>0;i--)
{
digitalWrite(Pin0, LOW); digitalWrite(Pin1, LOW); digitalWrite(Pin2, LOW); digitalWrite(Pin3, HIGH); delay(stepperSpeed);
digitalWrite(Pin0, LOW); digitalWrite(Pin1, LOW); digitalWrite(Pin2, HIGH); digitalWrite(Pin3, HIGH); delay(stepperSpeed);
digitalWrite(Pin0, LOW); digitalWrite(Pin1, LOW); digitalWrite(Pin2, HIGH); digitalWrite(Pin3, LOW); delay(stepperSpeed);
digitalWrite(Pin0, LOW); digitalWrite(Pin1, HIGH); digitalWrite(Pin2, HIGH); digitalWrite(Pin3, LOW); delay(stepperSpeed);
digitalWrite(Pin0, LOW); digitalWrite(Pin1, HIGH); digitalWrite(Pin2, LOW); digitalWrite(Pin3, LOW); delay(stepperSpeed);
digitalWrite(Pin0, HIGH); digitalWrite(Pin1, HIGH); digitalWrite(Pin2, LOW); digitalWrite(Pin3, LOW); delay(stepperSpeed);
digitalWrite(Pin0, HIGH); digitalWrite(Pin1, LOW); digitalWrite(Pin2, LOW); digitalWrite(Pin3, LOW); delay(stepperSpeed);
digitalWrite(Pin0, HIGH); digitalWrite(Pin1, LOW); digitalWrite(Pin2, LOW); digitalWrite(Pin3, HIGH); delay(stepperSpeed);
德晟智能
2024-09-04 广告
2024-09-04 广告
舵机伺服电机是一种在自动控制系统中广泛应用的执行元件。它具有快速响应、精准定位的特点,能够将电压信号转化为转矩和转速,以驱动控制对象。在东莞市德晟智能科技有限公司的产品中,舵机伺服电机扮演着重要的角色,广泛应用于各种精密电子设备、交通运输工...
点击进入详情页
本回答由德晟智能提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询