-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
33 lines (26 loc) · 1.28 KB
/
main.py
File metadata and controls
33 lines (26 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# PiicoDev VEML6040 minimal example code
# This program reads light data from the PiicoDev VEML6040 Colour Sensor
# Displays Raw Data, and classifies colours as fruits
from PiicoDev_VEML6040 import PiicoDev_VEML6040
from PiicoDev_Unified import sleep_ms # cross-platform compatible sleep function
# Associate a hue value with a fruit name
fruitList = {
"apple":0,
"carrot":60,
"lime":120
}
colourSensor = PiicoDev_VEML6040() # initialise the sensor
while True:
### Example 1: Print Raw RGB Data
data = colourSensor.readRGB() # Read the sensor (Colour space: Red Green Blue)
red = data['red'] # extract the RGB information from data
grn = data['green']
blu = data['blue']
print(str(blu) + " Blue " + str(grn) + " Green " + str(red) + " Red") # Print the data. Printing as BGR so the Thonny plot-colours match nicely :)
### Example 2: Classify the colour being shown - eg. a fruit sorting machine
# data = colourSensor.readHSV() # Read the sensor (Colour space: Hue Saturation Value)
# hue = data['hue'] # extract the Hue information from data
#
# label = colourSensor.classifyHue() # Read the sensor again, this time classify the colour
# print(str(label) + " Hue: " + str(hue)) # Show the label and the corresponding hue
sleep_ms(1000)