Je souhaite convertir un caractère ASCII en représentation pixel par pixel sur une…
- User
Je souhaite convertir un caractère ASCII en représentation pixel par pixel sur une matrice de LED. Ecris le code en C
Assistant
Voici un exemple de code en C qui convertit un caractère ASCII en représentation pixel par pixel sur une matrice de LED. Nous allons supposer que la matrice de LED est une matrice 8x8.
c#include <stdio.h> #include <string.h> // Défon de la police de caractères const unsigned char font[128][8] = { // 'A' { 0x00, 0x00, 0x1E, 0x11, 0x11, 0x1E, 0x00, 0x00 }, // 'B' { 0x00, 0x1F, 0x10, 0x10, 0x10, 0x1F, 0x00, 0x00 }, // 'C' { 0x00, 0x1E, 0x08, 0x08, 0x08, 0x1E, 0x00, 0x00 }, // ... // Insérer les données pour les autres caractères ici... }; // Fonction pour afficher un caractère sur la matrice de LED void afficherCaractere(char c, int matrice[8][8]) { int codeASCII = (int)c; if (codeASCII >= 0 && codeASCII < 128) { for (int i = 0; i < 8; i++) { matrice[i][0] = (font[codeASCII][] & 0x80) ? 1 : 0; matrice[i][1] = (font[codeASCII][i] & 0x40) ? 1 : 0; matrice[i][2] = (font[codeASCII][i] & 0x20) ? 1 : 0; matrice[i][3] = (font[codeASCII][i] & 0x10) ? 1 : 0; matrice[i][4] = (font[codeASCII][] & 0x08) ? 1 : 0; matrice[i][5] = (font[codeASCII][i] & 0x04) ? 1 : 0; matrice[i][6] = (font[codeASCII][i] & 0x02) ? 1 : 0; matrice[i][7] = (font[codeASCII][i] & 0x01) ? 1 : 0; } } else { printf("Caractère non supporté. "); } } // Fonction pour afficher la matrice de LED void afficherMatrice(int matrice[8][8]) { for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { printf("%d ", matrice[i][j]); } printf(" "); } } int main() { int matrice[8][8]; char c = 'A'; afficherCaractere(c, matrice); afficherMatrice(matrice); return 0; }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.