Created
June 24, 2024 15:48
-
-
Save maxpromer/f62db58805976ce22379ed53d8dea774 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define IN1_PIN 6 // กำหนดขาต่อ IN1 เป็นขา 6 | |
#define IN2_PIN 5 // กำหนดขาต่อ IN2 เป็นขา 5 | |
void setup() { | |
pinMode(IN1_PIN, OUTPUT); // กำหนดขาที่ IN1 เป็น OUTPUT | |
pinMode(IN2_PIN, OUTPUT); // กำหนดขาที่ IN2 เป็น OUTPUT | |
} | |
void loop() { | |
// กำหนดให้มอเตอร์หมุนตามเข็ม | |
analogWrite(IN1_PIN, 255); // ล็อกลอจิก IN1 = 1 | |
analogWrite(IN2_PIN, 127); // กำหนดความเร็ว 50% (50% = 127) | |
delay(1000); // ให้ค้างการทำงาน 1 วินาที | |
analogWrite(IN2_PIN, 0); // กำหนดความเร็ว 100% (100% = 0) | |
delay(1000); // ให้ค้างการทำงาน 1 วินาที | |
// กำหนดให้มอเตอร์หมุนทวนข็ม | |
analogWrite(IN1_PIN, 127); // กำหนดความเร็ว 50% (50% = 127) | |
analogWrite(IN2_PIN, 255); // ล็อกลอจิก IN2 = 1 | |
delay(1000); // ให้ค้างการทำงาน 1 วินาที | |
analogWrite(IN1_PIN, 0); // กำหนดความเร็ว 100% (100% = 0) | |
delay(1000); // ให้ค้างการทำงาน 1 วินาที | |
// กำหนดมอเตอร์หยุดหมุน | |
analogWrite(IN1_PIN, 255); // ล็อกลอจิก IN1 = 1 | |
analogWrite(IN2_PIN, 255); // ล็อกลอจิก IN2 = 1 | |
delay(1000); // ให้ค้างการทำงาน 1 วินาที | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment