สวิตช์กันชน#
การแนะนำ#
สวิตช์กันกระแทก เป็นสวิตช์เชิงกลที่ทำให้วงจรสมบูรณ์เมื่อถูกกด ทำให้หุ่นยนต์สามารถตรวจจับการกดและการปล่อยได้

หน้านี้ใช้ bumper_switch เป็นตัวอย่างชื่อสวิตช์กันชน โปรดแทนที่ด้วยชื่อที่คุณกำหนดเองตามต้องการ
ด้านล่างนี้คือรายการวิธีการที่มีให้เลือกใช้:
pressing– ส่งคืนว่าสวิตช์กันชนถูกกดหรือไม่pressed– ลงทะเบียนฟังก์ชันที่จะถูกเรียกเมื่อใดก็ตามที่กดสวิตช์กันชนreleased– ลงทะเบียนฟังก์ชันที่จะถูกเรียกเมื่อใดก็ตามที่ปล่อยสวิตช์กันชน
ตัวสร้าง – กำหนดค่าและตั้งค่าสวิตช์กันชนด้วยตนเอง
Bumper– สร้างสวิตช์กันชน
การกด#
pressing returns a Boolean indicating whether the Bumper Switch is currently being pressed. This can be used to check if the robot bumps into other objects.
True– สวิตช์กันชนกำลังถูกกดอยู่False– ไม่ได้กดสวิตช์กันชน
Usage:
bumper_switch.pressing()
พารามิเตอร์ |
คำอธิบาย |
|---|---|
เมธอดนี้ไม่มีพารามิเตอร์ |
# Display a message after bumper_switch is pressed
while not bumper_switch.pressing():
pass
brain.screen.print("Bumper Switch pressed!")
กด#
pressed registers a function to be called whenever the Bumper Switch is pressed.
Usage:
bumper_switch.pressed(callback, arg)
พารามิเตอร์ |
คำอธิบาย |
|---|---|
|
A previously defined function that executes when the Bumper Switch is pressed. |
|
ไม่บังคับ ทูเปิล |
def my_function():
brain.screen.print("Pressed")
# Call my_function whenever bumper_switch is pressed
bumper_switch.pressed(my_function)
ปล่อยแล้ว#
released ลงทะเบียนฟังก์ชันที่จะถูกเรียกใช้เมื่อใดก็ตามที่ปล่อยสวิตช์กันกระแทก
Usage:
bumper_switch.released(callback, arg)
พารามิเตอร์ |
คำอธิบาย |
|---|---|
|
A previously defined function that executes when the Bumper Switch is released. |
|
ไม่บังคับ ทูเปิล |
def my_function():
brain.screen.print("Released")
# Call my_function whenever bumper_switch is released
bumper_switch.released(my_function)
ผู้สร้าง#
ตัวสร้าง (Constructor) ใช้สำหรับสร้างอ็อบเจ็กต์ Bumper จำนวน ชิ้นด้วยตนเอง ซึ่งจำเป็นสำหรับการกำหนดค่า Bumper Switch นอก VEXcode
Bumper#
Bumper สร้างสวิตช์กันชน
Usage:
Bumper(port)
พารามิเตอร์ |
คำอธิบาย |
|---|---|
|
พอร์ต 3 สายที่เชื่อมต่อกับสวิตช์กันชน:
|
# Create a Bumper Switch in Port A
bumper_switch = Bumper(brain.three_wire_port.a)