Created
June 24, 2024 15:38
-
-
Save maxpromer/8770c033632f20a7cc5cec094c8030af to your computer and use it in GitHub Desktop.
This file contains hidden or 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 8 // กำหนดขาต่อ IN1 เป็นขา 8 | |
| #define IN2_PIN 7 // กำหนดขาต่อ IN2 เป็นขา 7 | |
| #define PWM_PIN 6 // กำหนดขาต่อ PWM เป็นขา 6 | |
| void setup() { | |
| pinMode(IN1_PIN, OUTPUT); // กำหนดขาที่ IN1 เป็น OUTPUT | |
| pinMode(IN2_PIN, OUTPUT); // กำหนดขาที่ IN2 เป็น OUTPUT | |
| pinMode(PWM_PIN, OUTPUT); // กำหนดขาที่ PWM เป็น OUTPUT | |
| } | |
| void loop() { | |
| // กำหนดให้มอเตอร์หมุนตามเข็ม | |
| digitalWrite(IN1_PIN, 1); // กำหนดลอจิก IN1 = 1 | |
| digitalWrite(IN2_PIN, 0); // กำหนดลอจิก IN2 = 0 | |
| analogWrite(PWM_PIN, 127); // กำหนดความเร็ว 50% (50% = 127) | |
| delay(1000); // ให้ค้างการทำงาน 1 วินาที | |
| analogWrite(PWM_PIN, 255); // กำหนดความเร็ว 100% (100% = 255) | |
| delay(1000); // ให้ค้างการทำงาน 1 วินาที | |
| // กำหนดให้มอเตอร์หมุนทวนข็ม | |
| digitalWrite(IN1_PIN, 0); // กำหนดลอจิก IN1 = 0 | |
| digitalWrite(IN2_PIN, 1); // กำหนดลอจิก IN2 = 1 | |
| analogWrite(PWM_PIN, 127); // กำหนดความเร็ว 50% | |
| delay(1000); // ให้ค้างการทำงาน 1 วินาที | |
| analogWrite(PWM_PIN, 255); // กำหนดความเร็ว 100% | |
| delay(1000); // ให้ค้างการทำงาน 1 วินาที | |
| // กำหนดมอเตอร์หยุดหมุน | |
| analogWrite(PWM_PIN, 0); // กำหนดความเร็ว 0% | |
| delay(1000); // ให้ค้างการทำงาน 1 วินาที | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment