JM9 XRCU Board 0.1.2
Libraries API Reference
Loading...
Searching...
No Matches
Color_sensor.h
Go to the documentation of this file.
1
14
15#ifndef COLOR_SENSOR_H
16#define COLOR_SENSOR_H
17
18#include <Arduino.h>
19#include <Wire.h>
20
21#include <Supported_sensor.h>
22
38enum color_t {
39 black = 0,
40 white = 1,
41 grey = 2,
42 red = 3,
43 green = 4,
44 blue = 5,
45 yellow = 6,
46 cyan = 7,
47 magenta = 8
48};
49
67struct rgbc_t {
74 uint32_t c;
75
79 uint32_t r;
80
84 uint32_t g;
85
89 uint32_t b;
90};
91
108struct hsl_t {
112 uint16_t h;
113
117 uint8_t s;
118
122 uint8_t l;
123};
124
141struct rgb_t {
145 uint8_t r;
146
150 uint8_t g;
151
155 uint8_t b;
156};
157
164uint16_t rgb888_to_rgb565 (rgb_t rgb888);
165
185 private:
189 const uint32_t port;
190
194 uint8_t i2c_address;
195
203 static const uint8_t DEFAULT_I2C_ADDRESS;
204
212 static const uint32_t I2C_FREQ;
213
222 bool send_cmd (const uint8_t cmd);
223
235 void i2c_request_by_cmd (const uint8_t cmd, uint8_t *const rx_buf, const size_t rx_buf_len);
236
237 public:
243 Color_sensor (const uint32_t init_port);
244
254 bool begin (const uint8_t init_i2c_address = DEFAULT_I2C_ADDRESS);
255
265 uint8_t get_color ();
266
276 rgb_t get_rgb ();
277
287 hsl_t get_hsl ();
288
298 rgbc_t get_rgbc ();
299
310 void turn_on_light_bulb ();
311
322 void turn_off_light_bulb ();
323
334 void turn_on_indicator_led ();
335
347
352 bool cal ();
353};
354
355#endif // #ifndef COLOR_SENSOR_H
color_t
Colors returnable by Color_sensor::get_color().
Definition Color_sensor.h:38
uint16_t rgb888_to_rgb565(rgb_t rgb888)
Converts an RGB-888 color to an RGB-565 color.
Definition Color_sensor.cpp:8
void turn_on_light_bulb()
Turns on the detector light bulb.
Definition Color_sensor.cpp:113
rgbc_t get_rgbc()
Gets the measured color in RGBC.
Definition Color_sensor.cpp:99
Color_sensor(const uint32_t init_port)
Creates a Color_sensor object.
Definition Color_sensor.cpp:50
void turn_off_indicator_led()
Turns off the indicator LED.
Definition Color_sensor.cpp:125
bool begin(const uint8_t init_i2c_address=DEFAULT_I2C_ADDRESS)
Activates this color sensor.
Definition Color_sensor.cpp:57
void turn_on_indicator_led()
Turns on the indicator LED.
Definition Color_sensor.cpp:121
uint8_t get_color()
Gets a simple color.
Definition Color_sensor.cpp:65
void turn_off_light_bulb()
Turns off the detector light bulb.
Definition Color_sensor.cpp:117
rgb_t get_rgb()
Gets the measured color in RGB-888.
Definition Color_sensor.cpp:71
hsl_t get_hsl()
Gets the measured color in HSL.
Definition Color_sensor.cpp:85
bool cal()
calibrates the color sensor to provide accurate results (for future compatibility use)
Definition Color_sensor.cpp:129
Supported_sensor()
Creates an object of a supported sensor.
Definition Supported_sensor.h:23
An HSL color.
Definition Color_sensor.h:108
uint8_t l
8-bit LIGHTNESS component in HSL [0 : 100].
Definition Color_sensor.h:122
uint8_t s
8-bit SATURATION component in HSL [0 : 100].
Definition Color_sensor.h:117
uint16_t h
16-bit HUE component in HSL [0 : 360].
Definition Color_sensor.h:112
An RGB-888 color.
Definition Color_sensor.h:141
uint8_t r
8-bit RED component in RGB-888 [0 : 255].
Definition Color_sensor.h:145
uint8_t g
8-bit GREEN component in RGB-888 [0 : 255].
Definition Color_sensor.h:150
uint8_t b
8-bit BLUE component in RGB-888 [0 : 255].
Definition Color_sensor.h:155
An RGBC color.
Definition Color_sensor.h:67
uint32_t g
32-bit GREEN component in RGBC.
Definition Color_sensor.h:84
uint32_t r
32-bit RED component in RGBC.
Definition Color_sensor.h:79
uint32_t c
32-bit CLEAR component in RGBC [0 : 65536].
Definition Color_sensor.h:74
uint32_t b
32-bit BLUE component in RGBC.
Definition Color_sensor.h:89