影片
TB6612FNG是東芝生產的馬達驅動與節制IC,內部包括兩組H橋式電路,可驅動和控制兩個小型直流馬達,或一個雙極性步進馬達。
水管清洗
水管清洗
程式實現
在申明程式之前
必需提到PWM會用到analogWrite
但是ESP32並不支援
所以改用LEDChannel代替
- int PWMA = 13;
- int INA1 = 12;
- int INA2 = 14;
- int STBY = 27;
- int INB1 = 25;
- int INB2 = 26;
- int PWMB = 33;
- const int ledPin = 2;
-
- void setup() {
- // put your setup code here, to run once:
- Serial.begin(115200);
- pinMode(ledPin, OUTPUT); //設定腳位為輸出
- pinMode(INA1,OUTPUT);
- pinMode(INA2,OUTPUT);
- pinMode(PWMA,OUTPUT);
- pinMode(STBY,OUTPUT);
- pinMode(INB1,OUTPUT);
- pinMode(INB2,OUTPUT);
- pinMode(PWMB,OUTPUT);
- //digital output test
- digitalWrite(INA1,HIGH); //設定腳位HIGH LOW
- digitalWrite(INA2,LOW);
- digitalWrite(PWMA,LOW);
- digitalWrite(STBY,HIGH);
- digitalWrite(INB1,HIGH);
- digitalWrite(INB2,LOW);
- digitalWrite(PWMB,LOW);
- delay(1000);
-
- //analog output(PWM) test 設定LED Channel PWM 頻率
- ledcSetup(0, 10000, 8);
- ledcSetup(1, 10000, 8);
- ledcSetup(2, 10000, 8);
- ledcSetup(3, 10000, 8);
- ledcSetup(4, 10000, 8);
- ledcSetup(5, 10000, 8);
- ledcSetup(6, 10000, 8);
- //設定腳位Channel
- ledcAttachPin(INA1, 0);
- ledcAttachPin(INA2, 1);
- ledcAttachPin(PWMA, 2);
- ledcAttachPin(STBY, 3);
- ledcAttachPin(INB1, 4);
- ledcAttachPin(INB2, 5);
- ledcAttachPin(PWMB, 6);
-
- }
-
- void loop() {
- // 起頭前先閃動ESP32板子上LED
- digitalWrite(ledPin,LOW);
- delay(500);
- digitalWrite(ledPin,HIGH);
- delay(500);
- digitalWrite(ledPin,LOW);
- //設定馬達1為正轉
- ledcWrite(0, 255); //INA1
- ledcWrite(1, 0); //INA2
- ledcWrite(2, 255); //PWMA
- ledcWrite(3, 255); //STBY
- //設定馬達2為正轉
- ledcWrite(4, 255); //INB1
- ledcWrite(5, 0); //INB2
- ledcWrite(6, 255); //PWMB
- delay(3000);
-
- digitalWrite(ledPin,LOW);
- delay(500);
- digitalWrite(ledPin,HIGH);
- delay(500);
- digitalWrite(ledPin,LOW);
- //設定馬達1為反轉
- ledcWrite(0, 0); //INA1
- ledcWrite(1, 255); //INA2
- ledcWrite(2, 255); //PWMA
- ledcWrite(3, 255); //STBY
- //設定馬達2為反轉
- ledcWrite(4, 0); //INB1
- ledcWrite(5, 255); //INB2
- ledcWrite(6, 255); //PWMB
- delay(3000);
- }
複製代碼
參考文章
https://swf.com.tw/?p=1066
文章出處:網頁設計,網站架設 ,網路行銷,網頁優化,SEO - NetYea 網頁設計
水管清洗
本篇文章引用自此:
留言列表