Programa C para controlar una matriz de 8x8 de LEDs para mostrar una serie de 0-9

Cómo escribir un programa en C para controlar una matriz 8x8 de LEDs para mostrar una serie de 0-9 en C Programación Sistemas Embedded ?


Programacion de sistemas embebidos

  1. // Programa Arduino
  2. // Control de una matriz de LEDs 8x8 para mostrar un numero de 0 a 9
  3. // Programacion de sistemas embebidos
  4.  
  5. // inicio de código
  6.  
  7. #include "LedControl.h"
  8. #define Pot A0
  9.  
  10. int DIN = 12;
  11. int CS =  10;
  12. int CLK = 11;
  13.  
  14.  
  15. byte cero[8]= {0x3C,0x7E,0x66,0x66,0x66,0x66,0x7E,0x3C,};
  16.  
  17.  
  18. byte numeros [10][8]= {{0x3C,0x7E,0x66,0x66,0x66,0x66,0x7E,0x3C,}, //0
  19.                       {0x38,0x38,0x18,0x18,0x18,0x18,0x3C,0x3C},  //1
  20.                       {0x1E,0x3F,0x77,0x66,0x0E,0x1C,0x3F,0x3F}, //2
  21.                       {0x7C,0x7C,0x0C,0x3C,0x3C,0x0C,0x7C,0x7C}, //3
  22.                       {0x1E,0x3E,0x76,0xE6,0xFF,0x7F,0x06,0x06},//4
  23.                       {0x3F,0x3F,0x30,0x3E,0x3F,0x03,0x3F,0x3E}, //5
  24.                       {0x3F,0x3F,0x30,0x3F,0x3F,0x33,0x3F,0x3F}, //6
  25.                       {0x3E,0x7E,0x66,0x06,0x06,0x06,0x06,0x06}, //7
  26.                       {0x3C,0x7E,0x66,0x66,0x7E,0x66,0x66,0x3C}, //8
  27.                       {0x3C,0x7E,0x66,0x66,0x7E,0x06,0x7E,0x3C}};//9
  28.  
  29. int pinPot = A0;    // Entrada para el potenciómetro.
  30. int valorPot = 0;   // variable para el valor del sensor.
  31. int pos = map (valorPot, 0, 1023, 0, 10);
  32.  
  33. #define NBR_MTX 2
  34. LedControl lc=LedControl(12,11,10, NBR_MTX);
  35. String digits= "1234567890";
  36. int digitCounter=0;
  37.  
  38. void setup() {
  39.   /*
  40.    The MAX72XX is in power-saving mode on startup,
  41.    we have to do a wakeup call
  42.    */
  43.    pinMode(pinPot, INPUT);
  44.   Serial.begin (9600);
  45.   Serial.println("Setup");
  46.   digitCounter=0;
  47.   for (int i=0; i< NBR_MTX; i++){
  48.     lc.shutdown(i,false);
  49.   /* Set the brightness to a medium values */
  50.     lc.setIntensity(i,1);
  51.   /* and clear the display */
  52.     lc.clearDisplay(i);
  53.   }
  54. }
  55.  
  56. void loop() {
  57.   // put your main code here, to run repeatedly:
  58. int Pos = analogRead(pinPot);
  59. Pos = map (Pos, 0, 1023, 0,10);
  60.   writeLetra(numeros[Pos]);
  61. Serial.println(pos);
  62.  
  63.  
  64. }
  65. void writeLetra (byte a[]){
  66.   for (int i = 0; i<8; i++){
  67.       lc.setRow(0,i,a[i]);
  68.  
  69.   }
  70.   delay(200);
  71.   for (int i = 0; i<8; i++){
  72.       lc.setRow(0,i,0);
  73.  
  74.   }
  75. }


Learn More :