สวิตช์กันชน#
การแนะนำ#
คลาส bumper ใช้สำหรับตรวจจับเมื่อกดและปล่อยสวิตช์กันชน
คอนสตรัคเตอร์คลาส#
bumper(
int32_t index );
ตัวทำลายคลาส#
ทำลายวัตถุ bumper และปล่อยทรัพยากรที่เกี่ยวข้อง
virtual ~bumper();
พารามิเตอร์#
พารามิเตอร์ |
พิมพ์ |
คำอธิบาย |
|---|---|---|
|
|
พอร์ตอัจฉริยะที่เชื่อมต่อกับสวิตช์กันชน จะเขียนในรูปแบบ |
ตัวอย่าง#
// Create a bumper instance in Port 1
bumper Bumper1 = bumper(PORT1);
ฟังก์ชันสมาชิก#
คลาส bumper ประกอบด้วยฟังก์ชันสมาชิกต่อไปนี้:
pressing— ส่งกลับหากกดสวิตช์กันชนpressed— ลงทะเบียนฟังก์ชันที่จะถูกเรียกเมื่อกดสวิตช์กันชนreleased— ลงทะเบียนฟังก์ชันที่จะถูกเรียกเมื่อปล่อยสวิตช์กันชน
ก่อนเรียกใช้ฟังก์ชันสมาชิก bumper ใดๆ จะต้องสร้างอินสแตนซ์ bumper ก่อน ดังแสดงด้านล่าง:
/* This constructor is required when using VS Code.
Bumper Switch configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */
// Create a bumper instance in Port 1
bumper Bumper1 = bumper(PORT1);
pressing#
ส่งคืนค่าหากขณะนี้กำลังกดสวิตช์กันชนอยู่
Available Functionsint32_t pressing();
ฟังก์ชันนี้ไม่รับพารามิเตอร์ใดๆ
Return Valuesส่งคืนค่า int32_t เพื่อระบุว่าสวิตช์กันชนถูกกดอยู่หรือไม่
1— สวิตช์กันชนกำลังถูกกด0— ไม่ได้กดสวิตช์กันชน
pressed#
ลงทะเบียนฟังก์ชันที่จะถูกเรียกใช้เมื่อกดสวิตช์กันชน
Available Functionsvoid pressed( void (* callback)(void) );
พารามิเตอร์ |
พิมพ์ |
คำอธิบาย |
|---|---|---|
|
|
ตัวชี้ไปยังฟังก์ชันที่จะถูกเรียกเมื่อกดปุ่มกันชน ฟังก์ชันนี้ต้องไม่มีพารามิเตอร์และส่งคืนค่าว่าง (void) |
ฟังก์ชันนี้ไม่ส่งค่ากลับ
Examplesกำหนดฟังก์ชันเรียกกลับ (นอก
int main())// Display a message when bumper is pressed void BumperPressed() { Brain.Screen.print("Bumper pressed"); }ลงทะเบียนฟังก์ชันเรียกกลับภายใน
int main()int main() { /* vexcodeInit() is only required when using VEXcode. Remove vexcodeInit() if compiling in VS Code. */ vexcodeInit(); // Run BumperPressed when the value of the Bumper Switch is pressed. Bumper1.pressed(BumperPressed); }
released#
ลงทะเบียนฟังก์ชันที่จะถูกเรียกเมื่อปล่อยสวิตช์กันชน
Available Functionsvoid released( void (* callback)(void) );
พารามิเตอร์ |
พิมพ์ |
คำอธิบาย |
|---|---|---|
|
|
ตัวชี้ไปยังฟังก์ชันที่จะถูกเรียกเมื่อปล่อยกันชน ฟังก์ชันนี้ต้องไม่มีพารามิเตอร์และส่งคืนค่าว่าง (void) |
ฟังก์ชันนี้ไม่ส่งค่ากลับ
Examplesกำหนดฟังก์ชันเรียกกลับ (นอก
int main())// Display a message when bumper is released void BumperReleased() { Brain.Screen.print("Bumper released"); }ลงทะเบียนฟังก์ชันเรียกกลับภายใน
int main()int main() { /* vexcodeInit() is only required when using VEXcode. Remove vexcodeInit() if compiling in VS Code. */ vexcodeInit(); // Run BumperReleased when the value of the Bumper Switch is released. Bumper1.released(BumperReleased); }