找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 8142|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

Arduino 電位器控制步進電機正反轉(zhuǎn)

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:426684 發(fā)表于 2018-12-7 09:17 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
Arduino 電位器控制步進電機正反轉(zhuǎn)

//電位器控制步進電機正反轉(zhuǎn)
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#include <Stepper.h>
const int stepsPerRevolution = 80;
Stepper myStepper(stepsPerRevolution, 7, 9, 8, 10);
const int aInPin=A0;  //電位器信號
int val;
void setup() {
myStepper.setSpeed(90);
Serial.begin(9600);
lcd.begin(16, 2);
}

void loop() {
val=analogRead(aInPin);
val=map(val,0,1023,0,99);
lcd.setCursor(0, 0);
lcd.print("val=");
lcd.setCursor(5, 0);
lcd.print(val);
//Serial.println(val);
// 如果阻值小于50 反時針轉(zhuǎn)
if(val<50){
lcd.setCursor(0, 1);
lcd.print("                ");
lcd.setCursor(0, 1);
lcd.print("counterclockwise");
//Serial.println("反時針");
myStepper.step(stepsPerRevolution);
delay(500);
}  else{
// 如果阻值大于50 順時針轉(zhuǎn)
lcd.setCursor(0, 1);
lcd.print("                ");
lcd.setCursor(0, 1);
lcd.print("clockwise");
//Serial.println("順時針");
myStepper.step(-stepsPerRevolution);
delay(500);
}
}

視頻:

https://pan.baidu.com/s/19WgWEnB7VyFKmbcZSehgkA



評分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表