สวิตช์จำกัด#
การแนะนำ#
สวิตช์จำกัด คือเซ็นเซอร์ดิจิทัลขนาดเล็กที่ตรวจจับการสัมผัสกับวัตถุ

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