2021-01-27 11:14:25 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include "pico/stdlib.h"
|
|
|
|
|
|
|
|
#include "bh1745.hpp"
|
|
|
|
|
|
|
|
using namespace pimoroni;
|
|
|
|
|
2021-07-12 13:21:14 +01:00
|
|
|
I2C i2c(BOARD::BREAKOUT_GARDEN);
|
|
|
|
BH1745 bh1745(&i2c, BH1745::DEFAULT_I2C_ADDRESS);
|
2021-01-27 11:14:25 +00:00
|
|
|
|
|
|
|
int main() {
|
2021-07-12 13:21:14 +01:00
|
|
|
stdio_init_all();
|
2021-01-27 11:14:25 +00:00
|
|
|
|
2021-07-12 15:26:41 +01:00
|
|
|
if (!bh1745.init()) {
|
2021-01-27 11:14:25 +00:00
|
|
|
printf("Failed to set up sensor\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t chip_id = bh1745.get_chip_id();
|
|
|
|
printf("Found BH1745. Chip ID: 0x%02x\n", chip_id);
|
|
|
|
|
|
|
|
bh1745.set_leds(true);
|
|
|
|
|
|
|
|
while(true) {
|
|
|
|
rgbc_t colour = bh1745.get_rgbc_raw();
|
|
|
|
printf("Colour: %d %d %d %d\n", colour.r, colour.g, colour.b, colour.c);
|
|
|
|
colour = bh1745.get_rgb_clamped();
|
|
|
|
printf("Clamped: %d %d %d %d\n", colour.r, colour.g, colour.b, colour.c);
|
|
|
|
colour = bh1745.get_rgb_scaled();
|
|
|
|
printf("Scaled: %d %d %d %d\n\n", colour.r, colour.g, colour.b, colour.c);
|
|
|
|
sleep_ms(1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|