Arduino EPS32 DEVKIT V1 用PWM節制
- int INA = 26;
- int INB = 27;
-
- void setup()
- {
- Serial.begin(9600);
- pinMode(INA,OUTPUT);
- pinMode(INB,OUTPUT);
- //digital output test
- Serial.println("INA=LOW,INB=HIGH");
- digitalWrite(INA,LOW);
- digitalWrite(INB,HIGH);
- delay(3000);
- Serial.println("INA=HIGH,INB=LOW");
- digitalWrite(INA,HIGH);
- digitalWrite(INB,LOW);
- delay(3000);
- Serial.println("INA=LOW,INB=LOW");
- digitalWrite(INA,LOW);
- digitalWrite(INB,LOW);
- delay(3000);
- Serial.println("INA=HIGH,INB=HIGH");
- digitalWrite(INA,HIGH);
- digitalWrite(INB,HIGH);
- delay(3000);
- //analog output(PWM) test
- ledcSetup(0, 5000, 8);
- ledcSetup(1, 5000, 8);
- ledcAttachPin(INA, 0);
- ledcAttachPin(INB, 1);
- //prepare forward
- Serial.println("INA=i++,INB=LOW");
- ledcWrite(1, 0);
- ledcWrite(0, 255);//避免電流太低沒法啟動
- delay(300);
- for (int i=80;i<=255;i++)
- {
- ledcWrite(0, i);
- ledcWrite(1, 0);
- Serial.println(i);
- delay(100);
- }
- ledcWrite(0, 0);
- ledcWrite(1, 0);
- delay(3000);
- //prepare reverse
- Serial.println("INA=LOW,INB=i++");
- ledcWrite(0, 0);
- ledcWrite(1, 255);//避免電流太低無法啟動
- delay(300);
- for (int i=80;i<=255;i++)
- {
- ledcWrite(1, i);
- ledcWrite(0, 0);
- Serial.println(i);
- delay(100);
- }
- ledcWrite(0, 0);
- ledcWrite(1, 0);
- delay(3000);
- }
-
- void loop()
- {
-
-
- }
複製代碼
Arduino EPS32 DEVKIT V1 腳位
影片
文章出處:網頁設計,網站架設 ,網路行銷,網頁優化,SEO - NetYea 網頁設計
利用L9110 Fan Motor,可以用PWM控制轉速,不會像DC馬達一路動吃掉電流,導致當機。
將INB、INA離別接在GPIO26及GPIO27上,INB與INA代表正反轉
數位輸出時成績
INA
|
INB
|
了局
|
HIGH
|
LOW
|
正轉
|
LOW
|
HIGH
|
反轉
|
LOW
|
LOW
|
截止
|
HIGH
|
HIGH
|
停止
|
類比輸出要注意的地方則是,由於電壓太低每每沒法啟動,所以先把output加到255,再從80逐步上升。
INA
|
INB
|
結果
|
80~255
|
LOW
|
慢慢增添正轉
|
LOW
|
80~255
|
漸漸增添反轉
|
文章來自: