2023-11-30 00:41:22 +00:00
|
|
|
#ifndef Utils
|
|
|
|
|
#define Utils
|
|
|
|
|
|
|
|
|
|
float fmap(float value, float fromLow, float fromHigh, float toLow, float toHigh)
|
|
|
|
|
{
|
|
|
|
|
// Verifique se o valor está fora dos limites e limite-o aos limites.
|
|
|
|
|
if (value < fromLow) {
|
|
|
|
|
value = fromLow;
|
|
|
|
|
} else if (value > fromHigh) {
|
|
|
|
|
value = fromHigh;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Calcule o valor mapeado.
|
|
|
|
|
float scale = (value - fromLow) / (fromHigh - fromLow);
|
|
|
|
|
float mappedValue = scale * (toHigh - toLow) + toLow;
|
|
|
|
|
|
|
|
|
|
return mappedValue;
|
|
|
|
|
}
|
2024-02-21 19:40:38 +00:00
|
|
|
|
|
|
|
|
byte stringToByte(String hexString) {
|
|
|
|
|
char hexChar[hexString.length() + 1]; // Cria um array de char para usar com strtol
|
|
|
|
|
hexString.toCharArray(hexChar, sizeof(hexChar)); // Converte a String para um array de char
|
|
|
|
|
long int number = strtol(hexChar, NULL, 16); // Converte de hexadecimal para long int
|
|
|
|
|
|
|
|
|
|
// Se você está certo de que o número cabe em um byte, você pode então converter para byte
|
|
|
|
|
byte numByte = (byte)number; // Converte o long int para byte
|
|
|
|
|
return numByte;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-30 00:41:22 +00:00
|
|
|
#endif
|