สวิตช์จำกัด#

การแนะนำ#

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

สวิตช์จำกัด VEX V5

หน้านี้ใช้ 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)

พารามิเตอร์

คำอธิบาย

callback

A previously defined function that executes when the Limit Switch is pressed.

arg

ไม่บังคับ ทูเปิล tuple ที่มีอาร์กิวเมนต์ที่จะส่งไปยังฟังก์ชันเรียกกลับ ดู ฟังก์ชันที่มีพารามิเตอร์ สำหรับข้อมูลเพิ่มเติม

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)

พารามิเตอร์

คำอธิบาย

callback

A previously defined function that executes when the Limit Switch is released.

arg

ไม่บังคับ ทูเปิล tuple ที่มีอาร์กิวเมนต์ที่จะส่งไปยังฟังก์ชันเรียกกลับ ดู ฟังก์ชันที่มีพารามิเตอร์ สำหรับข้อมูลเพิ่มเติม

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)

พารามิเตอร์

คำอธิบาย

port

พอร์ต 3 สายที่เชื่อมต่อกับสวิตช์จำกัด:

  • บน V5 Brain – brain.three_wire_port.x โดยที่ x คือหมายเลขของพอร์ต
  • บน 3-Wire Expander – expander.a โดยที่ expander คือชื่อของอินสแตนซ์ expander

# Create a Limit Switch in Port A
light_switch = Limit(brain.three_wire_port.a)