Función parpadeoLED: Parpadeo de un Led con tiempo de encendido y apagado.
// parpadeoLED(13,50,300,50);
void parpadeoLED(int pinLed, int numParpadeos, int tParON, int tParOFF){
for (int i=0; i < numParpadeos; i++) {
digitalWrite(pinLed, HIGH); // LED Encendido.
delay(tParON); // Tiempo encendido en ms. (tParON)
digitalWrite(pinLed, LOW); // LED Apagado.
delay(tParOFF); // Tiempo apagado en ms. (tParOFF)
}
}
Función fadeLED: Encendido y apagado gradual de un Led con tiempo de ON/OFF y velocidad.
// fadeLED(13,50,50,50,2000,1000);
void fadeLED(int pinLed, int numFade, int tFadON, int tFadOFF, int tON, int tOFF){
for (int i=0; i < numFade; i++) {
fadeLedON(pinLed,tFadON);
delay(tON); // Tiempo encendido en ms. (tON)
fadeLedOFF(pinLed,tFadOFF);
delay(tOFF); // Tiempo apagado en ms. (tOFF)
}
}
void fadeLedON(int pinLed, int tFadON){
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
analogWrite(pinLed, fadeValue);
delay(tFadON); // Velocidad de encendido en ms. (tFadON)
}
}
void fadeLedOFF(int pinLed, int tFadOFF){
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
analogWrite(pinLed, fadeValue);
delay(tFadOFF); // Velocidad de apagado en ms. (tFadON)
}
}
Función SerialPrintFloat: Muestra valores de tipo float.
void SerialPrintFloat(float f){
Serial.print((int)f);
Serial.print(".");
int decplace = (f - (int)f) * 100;
Serial.print(abs(decplace));
}
Función bin2dec: Convierte un número binario en decimal.
// x = bin2dec("00001101"); ->> x=13
int bin2dec(char *bin){
int b, k, m, n;
int len, sum = 0;
len = strlen(bin) - 1;
for(k = 0; k <= len; k++)
{
n = (bin[k] - '0'); // char a valor numérico. 0 o 1.
if ((n > 1) || (n < 0))
{
return (0);
}
for(b = 1, m = len; m > k; m--) // Conversión.
{
b *= 2;
}
sum = sum + n * b;
}
return(sum);
}
Función Pausa: Realiza una pausa de x Minutos, Segundos o Milisegundos.
// Pausa(10,'s');
void Pausa(int xTiempo, char xTipo){
for (int j=1; j<=xTiempo; j++){
switch (xTipo){
case 'm': // (m) milisegundos.
delay(1);
break;
case 's': // (s) segundos.
delay(1000);
break;
case 'M': // (M) Minutos.
delay(60000);
break;
default:
delay(1);
}
}
}
|