Χρώμα#

Εισαγωγή#

Ο Αισθητήρας Χρώματος είναι ένας οπτικός αισθητήρας που επιτρέπει στο ρομπότ σας να ανιχνεύει πότε υπάρχει ένα αντικείμενο, να αναγνωρίζει συγκεκριμένα χρώματα και να επιστρέφει οπτικά δεδομένα όπως φωτεινότητα και απόχρωση.

Μπορείτε επίσης να διαμορφώσετε τη φωτεινότητα του εσωτερικού φωτός του αισθητήρα. Αυτά τα εργαλεία είναι ιδανικά για προγράμματα που πρέπει να αντιδρούν σε χρωματιστά αντικείμενα, συνθήκες φωτισμού ή ανατροφοδότηση αισθητήρα σε πραγματικό χρόνο.

This page uses color_1 as the example Color Sensor name. Replace it with your own configured name as needed.

Παρακάτω είναι μια λίστα με όλες τις μεθόδους:

Ενέργειες — Εντοπισμός αντικειμένων με τον Αισθητήρα Χρώματος.

  • object_detected — Registers a function to be called when an object is detected.

Μεταλλαγμένοι — Τροποποιήστε τα φώτα στον Αισθητήρα Χρώματος.

  • set_light — Sets the Color Sensor’s LED to on, off, or a set brightness level.

  • set_light_power — Sets the brightness of the Color Sensor’s LED.

Λήπτες — Επιστρέφουν δεδομένα αντικειμένου με τον Αισθητήρα Χρώματος.

  • is_near_object — Returns whether an object is within range of the sensor.

  • color — Returns the hex code of the detected color.

  • brightness — Returns the detected brightness.

  • hue — Returns the detected hue value.

  • installed — Returns whether the Color Sensor is connected to the Brain.

Κατασκευαστές — Μη αυτόματη αρχικοποίηση και ρύθμιση παραμέτρων ενός Αισθητήρα Χρώματος.

Ενέργειες#

object_detected#

object_detected registers a function to be called when the Color Sensor detects an object.

Usage:
color_1.object_detected(callback, args)

Παράμετροι

Περιγραφή

callback

Μια συνάρτηση που έχει οριστεί προηγουμένως για εκτέλεση όταν ο Αισθητήρας Χρώματος ανιχνεύει ένα αντικείμενο.

args

Προαιρετικό. Μια πλειάδα που περιέχει ορίσματα για να μεταβιβαστούν στη συνάρτηση επανάκλησης. Δείτε Συναρτήσεις με Παραμέτρους για περισσότερες πληροφορίες.

Μεταλλάκτες#

set_light#

set_light sets the Color Sensor’s LED to on, off, or a set brightness level.

Usage:
color_1.set_light(value, units)

Παράμετροι

Περιγραφή

value

Specifies whether to turn the LED on or off using one of the following:

  • LedStateType.ON — Sets the LED’s brightness to 100%.
  • LedStateType.OFF — Sets the LED’s brightness to 0%.
Alternatively, a percent from 0 to 100 can be used to set the LED brightness. A value of 0 turns the LED off; any value above 0 turns it on at that brightness.

units

Optional. The unit that represents the brightness value: PERCENT.

# Turn the LED on and off forever
while True:
    color_1.set_light(LedStateType.ON)
    wait(0.5, SECONDS)
    color_1.set_light(LedStateType.OFF)
    wait(0.5, SECONDS)

# Turn the LED on and off forever
while True:
    color_1.set_light(LedStateType.ON, 75)
    wait(0.5, SECONDS)
    color_1.set_light(0)
    wait(0.5, SECONDS)

set_light_power#

set_light_power sets the brightness of the Color Sensor’s LED. If the LED is not already on, this method will also turn the LED on.

Usage:
color_1.set_light_power(value)

Παράμετροι

Περιγραφή

value

Η φωτεινότητα της λυχνίας LED ως ποσοστό από 0 έως 100. Η τιμή 0 απενεργοποιεί τη λυχνία LED.

# Turn the LED light on at different intensities
color_1.set_light_power(10)
wait(2, SECONDS)
color_1.set_light_power(100)

Αποκτητές#

is_near_object#

is_near_object returns a Boolean indicating whether the Color Sensor is within approximately 57 millimeters (2.25 inches) of an object. Detection depends on reflected light, so dark or non-reflective surfaces may not be detected reliably.

  • True — The detected object is within approximately 57 millimeters.

  • False — The detected object is not within approximately 57 millimeters.

Usage:
color_1.is_near_object()

Παράμετροι

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

color#

color returns the hex code of the detected color as a string in the format “Color” followed by two zeros and the color’s hex value.

Για παράδειγμα, η ανίχνευση του κόκκινου (#FF0000) θα επιστρέψει το “Χρώμα 00FF0000”.

Usage:
color_1.color()

Παράμετροι

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

# Display the currently detected hex value
while True:
    brain.screen.clear_screen()
    brain.screen.set_cursor(1, 1)
    brain.screen.print(color_1.color())
    wait(0.5,SECONDS)

brightness#

brightness returns how bright the detected color is, as an integer from 0% to 100%.

Ένα υψηλότερο ποσοστό σημαίνει ότι ο Αισθητήρας Χρώματος ανιχνεύει περισσότερο φως. Ένα χαμηλότερο ποσοστό σημαίνει ότι ο Αισθητήρας Χρώματος ανιχνεύει λιγότερο φως.

Usage:
color_1.brightness()

Παράμετροι

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

# Display the currently detected brightness
while True:
    brain.screen.clear_screen()
    brain.screen.set_cursor(1, 1)
    brain.screen.print("Brightness:")
    brain.screen.next_row()
    brain.screen.print(color_1.brightness())
    wait(0.5,SECONDS)

hue#

hue returns the detected hue value as a float in the range of 0 to 359.99 degrees.

Η απόχρωση είναι ένας τρόπος περιγραφής του χρώματος χρησιμοποιώντας αριθμούς γύρω από έναν χρωματικό κύκλο, όπως φαίνεται παρακάτω.

Ένας κυκλικός χρωματικός τροχός που εμφανίζει ένα πλήρες φάσμα αποχρώσεων με ετικέτες τιμών βαθμών γύρω από την περίμετρο, αυξανόμενες σε βήματα των 30 μοιρών από 0° στην κορυφή έως 360°.

Usage:
color_1.hue()

Παράμετροι

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

# Display the currently detected hue 
while True:
    brain.screen.clear_screen()
    brain.screen.set_cursor(1, 1)
    brain.screen.print("Hue: ")
    brain.screen.print(color_1.hue())
    wait(0.5,SECONDS)

installed#

installed returns a Boolean indicating whether the Color Sensor is connected to the Brain.

  • True — The Color Sensor is connected to the Brain.

  • False — The Color Sensor is not connected to the Brain.

Usage:
color_1.installed()

Παράμετροι

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

Κατασκευαστές#

Constructors are used to manually create ColorSensor objects, which are necessary for configuring a Color Sensor outside of VEXcode.

ColorSensor#

ColorSensor creates a Color Sensor.

Usage:
color_1 = ColorSensor(smartport)

Παράμετρος

Περιγραφή

smartport

Η Έξυπνη Θύρα στην οποία είναι συνδεδεμένος ο Αισθητήρας Χρώματος, γραμμένη ως PORTx όπου x είναι ο αριθμός της θύρας.

# Create a Color Sensor object in Port 3
color_1 = ColorSensor(Ports.PORT3)