I'm trying to get some library and test code that I grabbed from a website to run. I've added Serial.print statements to the test code (and removed LED write statements):
#include "fast_hsv2rgb.h"
uint16_t hue;
uint8_t val;
int8_t dir;
uint8_t prevtime;
void setup()
{
Serial.begin(9600);
hue = HSV_HUE_MIN;
val = HSV_VAL_MAX;
dir = -3;
prevtime = millis();
}
void loop()
{
uint8_t r, g, b;
uint8_t now = millis();
uint8_t tdiff = now - prevtime;
if(tdiff >= 5) {
prevtime = now; // Change color every 5ms
hue++; // Increase hue to circle and wrap
if(hue > HSV_HUE_MAX)
hue -= HSV_HUE_MAX;
val += dir; // Vary value between 1/4 and 4/4 of HSV_VAL_MAX
if(val < HSV_VAL_MAX / 4 || val == HSV_VAL_MAX)
dir = -dir; // Reverse value direction
// Perform conversion at fully saturated color
fast_hsv2rgb_32bit(hue, HSV_SAT_MAX, val, &r, &g, &b);
Serial.print("r = ");
Serial.print(r);
Serial.print(" g = ");
Serial.print(g);
Serial.print(" b = ");
Serial.println(b);
}
}
The first few lines of output are:
r = 0 g = 0 b = 0
09:34:36.821 -> r = 0 g = 0 b = 0
09:34:36.821 -> r = 0 g = 0 b = 0
09:34:36.859 -> r = 0 g = 0 b = 6
09:34:36.859 -> r = 0 g = 0 b = 1542
09:34:36.893 -> r = 0 g = 0 b = 394758
09:34:36.930 -> r = 0 g = 0 b = 101058054
09:34:36.964 -> r = 0 g = 6 b = 101058054
09:34:36.964 -> r = 0 g = 1542 b = 101058054
09:34:36.999 -> r = 0 g = 394758 b = 101058054
09:34:37.036 -> r = 0 g = 101058054 b = 101058054
Why am I getting those huge numbers? My understanding of uint8_t is an unsigned 8-bit integer, which should have a maximum value of 255. Can someone explain this to me? Thanks!