#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; } 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; } #endif