เอาต์พุต PWM#
การแนะนำ#
คลาส pwm_out ใช้สำหรับควบคุมเอาต์พุต PWM (Pulse Width Modulation) บนพอร์ต 3-Wire ของ VEX EXP ช่วยให้อุปกรณ์สามารถส่งสัญญาณพัลส์ที่มีความกว้างแปรผันไปยังส่วนประกอบ 3-Wire ที่เข้ากันได้
ตัวสร้างคลาส#
pwm_out(
triport::port &port );
ตัวทำลายคลาส#
ทำลายอ็อบเจ็กต์ pwm_out และปล่อยทรัพยากรที่เกี่ยวข้อง
~pwm_out();
พารามิเตอร์#
พารามิเตอร์ |
พิมพ์ |
คำอธิบาย |
|---|---|---|
|
|
พอร์ต 3 สายที่เชื่อมต่อกับเอาต์พุต PWM เขียนเป็น |
ตัวอย่าง#
// Create the pwm_out instance on 3-Wire Port A
pwm_out pwm = pwm_out(Brain.ThreeWirePort.A);
ฟังก์ชันสมาชิก#
คลาส pwm_out ประกอบด้วยฟังก์ชันสมาชิกต่อไปนี้:
state— กำหนดสถานะของเอาต์พุต PWM
ก่อนเรียกใช้ฟังก์ชันสมาชิก pwm_out ใดๆ จะต้องสร้างอินสแตนซ์ pwm_out ก่อน ดังแสดงด้านล่าง:
/* This constructor is required when using VS Code.
PWM configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */
// Create the pwm_out instance on 3-Wire Port A
pwm_out pwm = pwm_out(Brain.ThreeWirePort.A);
state#
ตั้งค่าสถานะของเอาต์พุต PWM ให้เป็นค่าที่ระบุไว้
Available Functionsvoid state(
int32_t value,
percentUnits units );
พารามิเตอร์ |
พิมพ์ |
คำอธิบาย |
|---|---|---|
|
|
ค่าใหม่ที่จะตั้งค่าสำหรับเอาต์พุต PWM คือ ตั้งแต่ -100 ถึง +100 เปอร์เซ็นต์ |
|
|
The unit used to represent the PWM value: |
ฟังก์ชันนี้ไม่ส่งค่ากลับ
Notesค่าเอาต์พุต PWM มีช่วงตั้งแต่ -100 ถึง +100 เปอร์เซ็นต์
หน่วยที่ถูกต้องเพียงหน่วยเดียวสำหรับเอาต์พุต PWM คือ
percent
// Set the PWM Output to 50%
pwm.state(50, percent);
// Set the PWM Output to -75%
pwm.state(-75, percent);