将十六进制字符串颜色转换为uint_16

时间:2019-10-28 02:44:42

标签: arduino

我需要将十六进制字符串转换为uint_16,以便将fillColor method用于m5Stack硬件。

我目前正在通过对https://m5stack.glitch.me/getColor的GET请求获取十六进制颜色值

我尝试过 uint16_t color = (uint16_t) strtol(http.getString(), NULL, 16);

但是出现错误 cannot convert 'String' to 'const char*' for argument '1' to 'long int strtol(const char*, char**, int)' 如何获取字符串十六进制颜色值并将其转换为uint_16?

1 个答案:

答案 0 :(得分:4)

strtol()无法将字符串对象作为输入。您必须将其转换为字符数组。

strtol(http.getString().c_str(), NULL, 16);