Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define TIMER 700
- #define PIN_U18 7
- #define ROWS 5
- #define MAX_COLS 4
- typedef struct Letter {
- int width;
- boolean data[ROWS][MAX_COLS];
- } Letter;
- int State = 0;
- int lastState = 0;
- Letter letters[25];
- void setup() {
- for (int pin = 2; pin <= 6; ++pin) {
- pinMode(pin, OUTPUT);
- }
- pinMode(PIN_U18, INPUT);
- // i'm using 'a' as an offset, this way the character 'a' will be stored in position 0
- // character 'a' corresponds to 97 (dec) and it'll be stored in position 97-97
- letters['t' - 'a'] = { // character 't' corresponds to 116-97=19, see: http://web.cs.mun.ca/~michael/c/ascii-table.html
- 3,
- {
- {1, 1, 1},
- {0, 1, 0},
- {0, 1, 0},
- {0, 1, 0},
- {0, 1, 0}
- }
- };
- letters['g' - 'a'] = {
- 4,
- {
- {1, 1, 1, 1},
- {1, 0, 0, 0},
- {1, 0, 1, 1},
- {1, 0, 0, 1},
- {1, 1, 1, 1}
- }
- };
- }
- void loop() {
- State = digitalRead(PIN_U18);
- if (State != lastState) {
- if (State == HIGH) {
- WriteString("tttggg");
- }
- }
- lastState = State;
- }
- void WriteString(const char *text) {
- while (*text != '\0') {
- WriteLetter(letters[*text]);
- ++text;
- }
- }
- void WriteLetter(Letter letter) {
- int pin;
- for (int col = 0; col < letter.width; ++col) {
- for (int row = 0; row < ROWS; ++row) {
- 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]
- digitalWrite(pin, letter.data[col][row]);
- }
- delayMicroseconds(TIMER);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement