Advertisement
parseint32

Untitled

Mar 27th, 2016
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.58 KB | None | 0 0
  1. #define TIMER     700
  2. #define PIN_U18   7
  3. #define ROWS      5
  4. #define MAX_COLS  4
  5.  
  6. typedef struct Letter {
  7.   int width;
  8.   boolean data[ROWS][MAX_COLS];
  9. } Letter;
  10.  
  11. int State = 0;
  12. int lastState = 0;
  13.  
  14. Letter letters[25];
  15.  
  16. void setup() {
  17.   for (int pin = 2; pin <= 6; ++pin) {
  18.     pinMode(pin, OUTPUT);
  19.   }
  20.   pinMode(PIN_U18, INPUT);
  21.  
  22.   // i'm using 'a' as an offset, this way the character 'a' will be stored in position 0
  23.   // character 'a' corresponds to 97 (dec) and it'll be stored in position 97-97
  24.   letters['t' - 'a'] = { // character 't' corresponds to 116-97=19, see: http://web.cs.mun.ca/~michael/c/ascii-table.html
  25.     3,
  26.     {
  27.       {1, 1, 1},
  28.       {0, 1, 0},
  29.       {0, 1, 0},
  30.       {0, 1, 0},
  31.       {0, 1, 0}
  32.     }
  33.   };
  34.  
  35.   letters['g' - 'a'] = {
  36.     4,
  37.     {
  38.       {1, 1, 1, 1},
  39.       {1, 0, 0, 0},
  40.       {1, 0, 1, 1},
  41.       {1, 0, 0, 1},
  42.       {1, 1, 1, 1}
  43.     }
  44.   };
  45. }
  46.  
  47. void loop() {
  48.   State = digitalRead(PIN_U18);
  49.   if (State != lastState) {
  50.     if (State == HIGH) {
  51.       WriteString("tttggg");
  52.     }
  53.   }
  54.   lastState = State;
  55. }
  56.  
  57. void WriteString(const char *text) {
  58.   while (*text != '\0') {
  59.     WriteLetter(letters[*text]);
  60.     ++text;
  61.   }
  62. }
  63.  
  64. void WriteLetter(Letter letter) {
  65.   int pin;
  66.   for (int col = 0; col < letter.width; ++col) {
  67.     for (int row = 0; row < ROWS; ++row) {
  68.       pin = row + 2; // if you can't use adjacent pins, you can make an array that contains the number of pins like that: a = {1,3,4,5,8} and then pin = a[row]
  69.       digitalWrite(pin, letter.data[col][row]);
  70.     }
  71.     delayMicroseconds(TIMER);
  72.   }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement