Paso 2: Programar tu Arduino
Subir el sketch de ejemplo proporcionados (abajo) a su Arduino. Asegúrese de nota los pines digitales utilizados.--------------------------------------
/*
Conexión un M74HC238 3-8 línea decodificador con un Arduino (ejemplo)
Cruz de Zach - 19 de octubre de 2011
*/
const int selA = 2;
const int selB = 3;
const int selC = 4;
const int permitir = 5;
int incomingByte;
void setup()
{
inicializar la comunicación serial:
Serial.Begin(9600);
inicializar las salidas de control
pinMode (selA, salida);
pinMode (selB, salida);
pinMode (selC, salida);
digitalWrite (selA, LOW);
digitalWrite (selB, LOW);
digitalWrite (selC, LOW);
digitalWrite (habilitar, HIGH);
}
void loop()
{
Si (Serial.available() > 0) {}
incomingByte = Serial.read();
Si (incomingByte == '0') {}
digitalWrite (habilitar, LOW);
digitalWrite (selC, LOW);
digitalWrite (selB, LOW);
digitalWrite (selA, LOW);
Serial.println ("LED 0 verde: alta");
} else if (incomingByte == '1') {}
digitalWrite (habilitar, LOW);
digitalWrite (selC, LOW);
digitalWrite (selB, LOW);
digitalWrite (selA, HIGH);
Serial.println ("LED verde 1: alta");
} else if (incomingByte == '2') {}
digitalWrite (habilitar, LOW);
digitalWrite (selC, LOW);
digitalWrite (selB, HIGH);
digitalWrite (selA, LOW);
Serial.println ("amarillo LED 2: alta");
} else if (incomingByte == '3') {}
digitalWrite (habilitar, LOW);
digitalWrite (selC, LOW);
digitalWrite (selB, HIGH);
digitalWrite (selA, HIGH);
Serial.println ("LED 3 amarillo: alta");
} else if (incomingByte == '4') {}
digitalWrite (habilitar, LOW);
digitalWrite (selC, HIGH);
digitalWrite (selB, LOW);
digitalWrite (selA, LOW);
Serial.println ("LED rojo 4: alta");
} else if (incomingByte == "5") {}
digitalWrite (habilitar, LOW);
digitalWrite (selC, HIGH);
digitalWrite (selB, LOW);
digitalWrite (selA, HIGH);
Serial.println ("LED 5 rojo: alta");
} else if (incomingByte == '6') {}
digitalWrite (habilitar, LOW);
digitalWrite (selC, HIGH);
digitalWrite (selB, HIGH);
digitalWrite (selA, LOW);
Serial.println ("Y6: alta");
} else if (incomingByte == '7') {}
digitalWrite (habilitar, LOW);
digitalWrite (selC, HIGH);
digitalWrite (selB, HIGH);
digitalWrite (selA, HIGH);
Serial.println ("Y7: alta");
} else if (incomingByte == '8') {}
digitalWrite (habilitar, HIGH);
Serial.println ("personas con discapacidad, todas de LEDS de baja");
}
}
}
---------------------------------------------------------------------