Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********** Proyecto **********
- * Laboratorio 6
- * Autor: Josue Mauricio Hurtado Mosquera
- * Descripcion:
- * Controlar 8 LEDs desde el Arduino, a través de un IC 74HC595, definiendo mínimo 8 patrones de movimiento que son controlados desde
- * una interfaz gráfica en Processing/ControlP5. Más información sobre el IC 74HC595
- */
- /********** Variables **********/
- // se inicializan los pines para en envio de los datos al integrado
- int latchPin = 11;
- int clockPin = 10;
- int dataPin = 9;
- // se inicializan los arreglos para cada patrón
- int P1[13] = {0, 1, 5, 21, 85, 213, 245, 253, 255, 0};
- int P2[9] = {0, 1, 129, 131, 195, 199, 239, 129, 0 };
- int P3[9] = {0, 129, 66, 36, 24, 36, 66, 129, 0 };
- int P4[9] = {0, 3, 15, 63, 255, 243, 240, 192, 0};
- int P5[10] = {0, 1, 5, 21, 85, 213, 245, 253, 255, 0};
- int P6[17] = {0, 240, 255, 15, 255, 15, 255, 240, 0, 2, 8, 16, 66, 32, 129, 195};
- int P7[7] = {0, 255, 189, 165, 161, 129, 0};
- int P8[16] = {0, 2, 4, 8, 16, 32, 64, 128, 64, 32, 16, 8, 4, 2, 1, 0};
- char Letra; // variable para la lectura del dato serial desde processing
- /********** Configuracion **********/
- void setup() {
- // se configuran los pines como salidas y el modulo de com serial
- pinMode(latchPin, OUTPUT);
- pinMode(dataPin, OUTPUT);
- pinMode(clockPin, OUTPUT);
- Serial.begin(9600);
- }//end setup ()
- void loop() {
- // Si hay datos disponibles en el puerto serial
- if (Serial.available() > 0)
- {
- // Leer la letra actual en el buffer
- Letra = Serial.read();
- // aqui se condiciona si la letra enviada está entre las opciones y ejecuta el patron determinado
- if (Letra == 'A') {
- for (int j = 0; j < 13; j++) {
- envio(P1[j]);
- }
- }
- if (Letra == 'B') {
- for (int j = 0; j < 9; j++) {
- envio(P2[j]);
- }
- }
- if (Letra == 'C') {
- for (int j = 0; j < 9; j++) {
- envio(P3[j]);
- }
- }
- if (Letra == 'D') {
- for (int j = 0; j < 9; j++) {
- envio(P4[j]);
- }
- }
- if (Letra == 'E') {
- for (int j = 0; j < 10; j++) {
- envio(P5[j]);
- }
- }
- if (Letra == 'F') {
- for (int j = 0; j < 17; j++) {
- envio(P6[j]);
- }
- }
- if (Letra == 'G') {
- for (int j = 0; j < 7; j++) {
- envio(P7[j]);
- }
- }
- if (Letra == 'H') {
- for (int j = 0; j < 16; j++) {
- envio(P8[j]);
- }
- }
- // el bucle se ejecuta mientras hayan datos disponibles por leer en el buffer.
- }
- } //end loop ()
- void envio(int data) { //Configuracion de envio de datos al integrado
- digitalWrite(latchPin, LOW);
- shiftOut(dataPin, clockPin, MSBFIRST, data);
- digitalWrite(latchPin, HIGH);
- delay(200);
- } //end envio ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement