เอาต์พุต PWM#

การแนะนำ#

คลาส pwm_out ใช้สำหรับควบคุมเอาต์พุต PWM (Pulse Width Modulation) บนพอร์ต 3-Wire ของ VEX V5 ช่วยให้อุปกรณ์สามารถส่งสัญญาณพัลส์ที่มีความกว้างแปรผันไปยังส่วนประกอบ 3-Wire ที่เข้ากันได้

ตัวสร้างคลาส#

pwm_out(
  triport::port &port );

ตัวทำลายคลาส#

ทำลายอ็อบเจ็กต์ pwm_out และปล่อยทรัพยากรที่เกี่ยวข้อง

~pwm_out();

พารามิเตอร์#

พารามิเตอร์

พิมพ์

คำอธิบาย

port

triport::port &

พอร์ต 3 สายที่เชื่อมต่อกับเอาต์พุต PWM เขียนเป็น Brain.ThreeWirePort.X หรือ ExpanderName.Xโดยที่ X คือตัวอักษรของพอร์ต (ตัวอย่างเช่น Brain.ThreeWirePort.A หรือ Expander1.A)

ตัวอย่าง#

// 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 Functions
void state(
  int32_t      value,
  percentUnits units );

Parameters

พารามิเตอร์

พิมพ์

คำอธิบาย

value

int32_t

ค่าใหม่ที่จะตั้งค่าสำหรับเอาต์พุต PWM คือ ตั้งแต่ -100 ถึง +100 เปอร์เซ็นต์

units

percentUnits

The unit used to represent the PWM value: percent / pct — percent

Return Values

ฟังก์ชันนี้ไม่ส่งค่ากลับ

Notes
  • ค่าเอาต์พุต PWM มีช่วงตั้งแต่ -100 ถึง +100 เปอร์เซ็นต์

  • หน่วยที่ถูกต้องเพียงหน่วยเดียวสำหรับเอาต์พุต PWM คือ percent

Examples
// Set the PWM Output to 50%
pwm.state(50, percent);

// Set the PWM Output to -75%
pwm.state(-75, percent);