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
- // Programa Arduino
- // Control de una matriz de LEDs 8x8 para mostrar un numero de 0 a 9
- // Programacion de sistemas embebidos
- // inicio de código
- #include "LedControl.h"
- #define Pot A0
- int DIN = 12;
- int CS = 10;
- int CLK = 11;
- byte cero[8]= {0x3C,0x7E,0x66,0x66,0x66,0x66,0x7E,0x3C,};
- byte numeros [10][8]= {{0x3C,0x7E,0x66,0x66,0x66,0x66,0x7E,0x3C,}, //0
- {0x38,0x38,0x18,0x18,0x18,0x18,0x3C,0x3C}, //1
- {0x1E,0x3F,0x77,0x66,0x0E,0x1C,0x3F,0x3F}, //2
- {0x7C,0x7C,0x0C,0x3C,0x3C,0x0C,0x7C,0x7C}, //3
- {0x1E,0x3E,0x76,0xE6,0xFF,0x7F,0x06,0x06},//4
- {0x3F,0x3F,0x30,0x3E,0x3F,0x03,0x3F,0x3E}, //5
- {0x3F,0x3F,0x30,0x3F,0x3F,0x33,0x3F,0x3F}, //6
- {0x3E,0x7E,0x66,0x06,0x06,0x06,0x06,0x06}, //7
- {0x3C,0x7E,0x66,0x66,0x7E,0x66,0x66,0x3C}, //8
- {0x3C,0x7E,0x66,0x66,0x7E,0x06,0x7E,0x3C}};//9
- int pinPot = A0; // Entrada para el potenciómetro.
- int valorPot = 0; // variable para el valor del sensor.
- int pos = map (valorPot, 0, 1023, 0, 10);
- #define NBR_MTX 2
- LedControl lc=LedControl(12,11,10, NBR_MTX);
- String digits= "1234567890";
- int digitCounter=0;
- void setup() {
- /*
- The MAX72XX is in power-saving mode on startup,
- we have to do a wakeup call
- */
- pinMode(pinPot, INPUT);
- Serial.begin (9600);
- Serial.println("Setup");
- digitCounter=0;
- for (int i=0; i< NBR_MTX; i++){
- lc.shutdown(i,false);
- /* Set the brightness to a medium values */
- lc.setIntensity(i,1);
- /* and clear the display */
- lc.clearDisplay(i);
- }
- }
- void loop() {
- // put your main code here, to run repeatedly:
- int Pos = analogRead(pinPot);
- Pos = map (Pos, 0, 1023, 0,10);
- writeLetra(numeros[Pos]);
- Serial.println(pos);
- }
- void writeLetra (byte a[]){
- for (int i = 0; i<8; i++){
- lc.setRow(0,i,a[i]);
- }
- delay(200);
- for (int i = 0; i<8; i++){
- lc.setRow(0,i,0);
- }
- }