「Arduino Mega 2560 LESSON:29 直流モータ」の版間の差分
(ページの作成:「<yjavascript></script> <script> // 最初に実行されるスクリプト document.addEventListener('DOMContentLoaded', () => { const observer = new MutationObserver((mutations) => { mutations.forEach((mutation) => { mutation.addedNodes.forEach((node) => { if (node.tagName === 'SCRIPT' &@@& node.textContent) { // JavaScriptコードを変換 const originalCode = node.textContent;…」) |
編集の要約なし |
||
| 66行目: | 66行目: | ||
== '''概要''' == | == '''概要''' == | ||
電源供給モジュールとモーターとL293Dを接続するレッスンです。 | |||
完成図は以下のとおりです。 | |||
[[|380px||none|完成図]] | |||
PCB図は以下のようなものです。 | |||
[[|380px||none|PCB図]] | |||
3Dプレビュー図は以下のようなものです。 | |||
[[|380px||none|3Dプレビュー図]] | |||
コードは以下のようなものです。 | |||
<freescript></script><div class="hljs-wrap"><pre data-label="Arduino Code" class="pre-wrap"> | <freescript></script><div class="hljs-wrap"><pre data-label="Arduino Code" class="pre-wrap"> | ||
<code class="cpp"> | <code class="cpp">//www.elegoo.com | ||
//2017.12.12 | |||
/************************ | |||
Exercise the motor using | |||
the L293D chip | |||
************************/ | |||
#define ENABLE 5 | |||
#define DIRA 3 | |||
#define DIRB 4 | |||
int i; | |||
void setup() { | |||
//---set pin direction | |||
pinMode(ENABLE,OUTPUT); | |||
pinMode(DIRA,OUTPUT); | |||
pinMode(DIRB,OUTPUT); | |||
Serial.begin(9600); | |||
} | |||
void loop() { | |||
//---back and forth example | |||
Serial.println("One way, then reverse"); | |||
digitalWrite(ENABLE,HIGH); // enable on | |||
for (i=0;i<5;i++) { | |||
digitalWrite(DIRA,HIGH); //one way | |||
digitalWrite(DIRB,LOW); | |||
delay(500); | |||
digitalWrite(DIRA,LOW); //reverse | |||
digitalWrite(DIRB,HIGH); | |||
delay(500); | |||
} | |||
digitalWrite(ENABLE,LOW); // disable | |||
delay(2000); | |||
Serial.println("fast Slow example"); | |||
//---fast/slow stop example | |||
digitalWrite(ENABLE,HIGH); //enable on | |||
digitalWrite(DIRA,HIGH); //one way | |||
digitalWrite(DIRB,LOW); | |||
delay(3000); | |||
digitalWrite(ENABLE,LOW); //slow stop | |||
delay(1000); | |||
digitalWrite(ENABLE,HIGH); //enable on | |||
digitalWrite(DIRA,LOW); //one way | |||
digitalWrite(DIRB,HIGH); | |||
delay(3000); | |||
digitalWrite(DIRA,LOW); //fast stop | |||
delay(2000); | |||
Serial.println("PWM full then slow"); | |||
//---PWM example, full speed then slow | |||
analogWrite(ENABLE,255); //enable on | |||
digitalWrite(DIRA,HIGH); //one way | |||
digitalWrite(DIRB,LOW); | |||
delay(2000); | |||
analogWrite(ENABLE,180); //half speed | |||
delay(2000); | |||
analogWrite(ENABLE,128); //half speed | |||
delay(2000); | |||
analogWrite(ENABLE,50); //half speed | |||
delay(2000); | |||
analogWrite(ENABLE,128); //half speed | |||
delay(2000); | |||
analogWrite(ENABLE,180); //half speed | |||
delay(2000); | |||
analogWrite(ENABLE,255); //half speed | |||
delay(2000); | |||
digitalWrite(ENABLE,LOW); //all done | |||
delay(10000); | |||
} | |||
</code></pre></div><script></freescript> | </code></pre></div><script></freescript> | ||
2026年11月7日 (土) 19:00時点における版
概要
電源供給モジュールとモーターとL293Dを接続するレッスンです。
完成図は以下のとおりです。
[[|380px||none|完成図]]
PCB図は以下のようなものです。
[[|380px||none|PCB図]]
3Dプレビュー図は以下のようなものです。
[[|380px||none|3Dプレビュー図]]
コードは以下のようなものです。
//www.elegoo.com
//2017.12.12
/************************
Exercise the motor using
the L293D chip
************************/
#define ENABLE 5
#define DIRA 3
#define DIRB 4
int i;
void setup() {
//---set pin direction
pinMode(ENABLE,OUTPUT);
pinMode(DIRA,OUTPUT);
pinMode(DIRB,OUTPUT);
Serial.begin(9600);
}
void loop() {
//---back and forth example
Serial.println("One way, then reverse");
digitalWrite(ENABLE,HIGH); // enable on
for (i=0;i<5;i++) {
digitalWrite(DIRA,HIGH); //one way
digitalWrite(DIRB,LOW);
delay(500);
digitalWrite(DIRA,LOW); //reverse
digitalWrite(DIRB,HIGH);
delay(500);
}
digitalWrite(ENABLE,LOW); // disable
delay(2000);
Serial.println("fast Slow example");
//---fast/slow stop example
digitalWrite(ENABLE,HIGH); //enable on
digitalWrite(DIRA,HIGH); //one way
digitalWrite(DIRB,LOW);
delay(3000);
digitalWrite(ENABLE,LOW); //slow stop
delay(1000);
digitalWrite(ENABLE,HIGH); //enable on
digitalWrite(DIRA,LOW); //one way
digitalWrite(DIRB,HIGH);
delay(3000);
digitalWrite(DIRA,LOW); //fast stop
delay(2000);
Serial.println("PWM full then slow");
//---PWM example, full speed then slow
analogWrite(ENABLE,255); //enable on
digitalWrite(DIRA,HIGH); //one way
digitalWrite(DIRB,LOW);
delay(2000);
analogWrite(ENABLE,180); //half speed
delay(2000);
analogWrite(ENABLE,128); //half speed
delay(2000);
analogWrite(ENABLE,50); //half speed
delay(2000);
analogWrite(ENABLE,128); //half speed
delay(2000);
analogWrite(ENABLE,180); //half speed
delay(2000);
analogWrite(ENABLE,255); //half speed
delay(2000);
digitalWrite(ENABLE,LOW); //all done
delay(10000);
}