LPC1768 programm for the led matrix.
Dependencies: BufferedSerial DS3231 mbed-rtos mbed
Diff: setMatrix.cpp
- Revision:
- 2:d5472e4a55bf
- Child:
- 3:bd1352d4dbb8
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/setMatrix.cpp Wed Oct 12 13:22:19 2016 +0000 @@ -0,0 +1,544 @@ +#include "initalize.h" +#include "alphabet.h" +#include "mbed.h" +#include <string> + +/* + __ __ _ _ _ + \ \ / /_ _ _ _(_)__ _| |__| |___ ___ + \ V / _` | '_| / _` | '_ \ / -_|_-< + \_/\__,_|_| |_\__,_|_.__/_\___/__/ + +*/ + +int m_speed, m_loop; + +int c_frame, // frame-counter + speed, // Variable for setting up, how fast the matrix would scroll + ble, // Variable as "getting text from Bluetooth"-signal + frames; // Variable for the scrolling of the text +string text_bluetooth (""); // will be empty, is going to be used for the bluetooth module +//------------------------------------------------------------------------------------------------------ + +DigitalOut ds1(p5), oe1(p6), stcp1(p7), shcp1(p8), mr1(p9), led(LED1); +AnalogIn ain(p20); +Ticker tick; +Serial pc(USBTX, USBRX); // tx, rx +/* +DS normal Serial Data Output Schreibt vor ob das LED 0 oder 1 ist. +OE invertiert Output-Enable Aktiviert oder deaktiviert die LEDs. +SHCP normal Shift register clk Setzt Position mit kurzen Impulsen fest. +STCP normal Storage reg. clk Setzt Reihe mit kurzen Impulsen fest. +MR invertiert Master reset resetet den Storage. Muss mit STCP angezeigt werden. +*/ +//------------------------------------------------------------------------------------------------------ +/* + ___ _ _ + | __| _ _ _ __| |_(_)___ _ _ ___ + | _| || | ' \/ _| _| / _ \ ' \(_-< + |_| \_,_|_||_\__|\__|_\___/_||_/__/ + +*/ + +void Matrix(int m_length, int m_height, int *matrix_text,const string text_generic) +{ + init(); + wait(0.5); + reset_srg(); + wait(0.05); + setText(text_generic,matrix_text); + wait(0.05); + setMatrix(m_height, m_length, matrix_text); +} + +void init() +{ + mr1 = 1; + oe1 = 0; + ds1 = 0; + stcp1 = 0; + shcp1 = 0; + frames = 0; + c_frame = 0; + m_loop = 1; +} + + +void shift_srg() +{ + wait_ms(0.05); // Perioden-Dauer 2ms, später verkürzen + shcp1 = 1; + wait_ms(0.05); + shcp1 = 0; +} + +void reset_srg() +{ + mr1 = 0; + wait_ms(0.05); // Reset-Puls 1ms, später verkürzen + mr1 = 1; +} + + +void setSpeed() +{ + // not possible with simple if-loops + if(ain > 0.125f) + m_speed = 10; + if(ain > 0.25f) + m_speed = 25; + if(ain > 0.375f) + m_speed = 50; + if(ain > 0.5f) + m_speed = 100; + if(ain > 0.625f) + m_speed = 250; + if(ain > 0.75f) + m_speed = 500; + if(ain > 0.875f) + m_speed = 1000; + if(ain > 0.97f) + m_speed = 2000; +} + + +void setMatrix(int m_height,int m_length, int *matrix_text) +{ + //bool row_temp[m_height]; // temporary array for matrix output + + while(1) + { + for(int frequency = 0; frequency < 50; frequency++) + { + for(int position = 0; position < m_length; position++) + { + for(int column = 0; column < m_length; column++) + { + if(column == position) + { + ds1 = 1; + } + else + { + ds1 = 0; + } + shift_srg(); + } + + for(int shift_int = 0; shift_int < m_height; shift_int++) + { + ds1 = (matrix_text[position] >> shift_int) & 1; + shift_srg(); + } + stcp1 = 1; + wait_ms(0.5); + stcp1 = 0; + } + } + frames++; + if(frames == c_frame) + frames = 0; + } +} + + +void initArray(int const *letter, int size, int *matrix_text) +{ + c_frame = c_frame + 1; // A small space, about 1 led column, is being added. + + for(int position = 0; position < size; position++) + { + matrix_text[c_frame] = letter[position]; + c_frame++; + } + matrix_text[c_frame] = 0x00; +} + +void setText(const string& text_dummy, int *matrix_text) +// Used to identifiy which letter is in the set String-Position. +// If it contains a specific letter, it will call another Function called "initArray" to fill up the array which is then used to show the letters on the Matrix +{ + for(int LetterPos = 0; LetterPos < text_dummy.size(); LetterPos++) + { + //Letters ------------------------ + if (text_dummy.at(LetterPos) == 'A') + { + initArray(A,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'a') + { + initArray(a,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'B') + { + initArray(B,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'b') + { + initArray(b,5,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'C') + { + initArray(C,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'c') + { + initArray(c,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'D') + { + initArray(D,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'd') + { + initArray(d,5,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'E') + { + initArray(E,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'e') + { + initArray(e,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'F') + { + initArray(F,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'f') + { + initArray(f,3,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'G') + { + initArray(G,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'g') + { + initArray(g,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'H') + { + initArray(H,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'h') + { + initArray(h,5,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'I') + { + initArray(I,3,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'i') + { + initArray(i,3,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'J') + { + initArray(J,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'j') + { + initArray(j,3,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'K') + { + initArray(K,5,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'k') + { + initArray(k,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'L') + { + initArray(L,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'l') + { + initArray(l,3,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'M') + { + initArray(M,5,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'm') + { + initArray(m,5,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'N') + { + initArray(N,5,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'n') + { + initArray(n,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'O') + { + initArray(O,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'o') + { + initArray(o,5,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'P') + { + initArray(P,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'p') + { + initArray(p,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'Q') + { + initArray(Q,5,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'q') + { + initArray(q,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'R') + { + initArray(R,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'r') + { + initArray(r,3,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'S') + { + initArray(S,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == 's') + { + initArray(s,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'T') + { + initArray(T,5,matrix_text); + } + else if(text_dummy.at(LetterPos) == 't') + { + initArray(t,3,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'U') + { + initArray(U,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'u') + { + initArray(u,5,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'V') + { + initArray(V,5,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'v') + { + initArray(v,5,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'W') + { + initArray(W,5,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'w') + { + initArray(w,5,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'X') + { + initArray(X,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'x') + { + initArray(x,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'Y') + { + initArray(Y,5,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'y') + { + initArray(y,5,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'Z') + { + initArray(Z,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == 'z') + { + initArray(z,4,matrix_text); + } + // Numbers ----------------------- + else if(text_dummy.at(LetterPos) == '0') + { + initArray(zero,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == '1') + { + initArray(one,3,matrix_text); + } + else if(text_dummy.at(LetterPos) == '2') + { + initArray(two,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == '3') + { + initArray(three,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == '4') + { + initArray(four,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == '5') + { + initArray(five,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == '6') + { + initArray(six,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == '7') + { + initArray(seven,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == '8') + { + initArray(eight,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == '9') + { + initArray(nine,4,matrix_text); + } + // Symbols ----------------------- + else if(text_dummy.at(LetterPos) == '!') + { + initArray(exclam,1,matrix_text); + } + else if(text_dummy.at(LetterPos) == '?') + { + initArray(quest,3,matrix_text); + } + else if(text_dummy.at(LetterPos) == 34) + { + initArray(quote,3,matrix_text); + } + else if(text_dummy.at(LetterPos) == '#') + { + initArray(hash,5,matrix_text); + } + else if(text_dummy.at(LetterPos) == '$') + { + initArray(dollar,5,matrix_text); + } + else if(text_dummy.at(LetterPos) == '%') + { + initArray(prcent,7,matrix_text); + } + else if(text_dummy.at(LetterPos) == '&') + { + initArray(_and,5,matrix_text); + } + else if(text_dummy.at(LetterPos) == '(') + { + initArray(round_o,2,matrix_text); + } + else if(text_dummy.at(LetterPos) == ')') + { + initArray(round_c,2,matrix_text); + } + else if(text_dummy.at(LetterPos) == '*') + { + initArray(star,5,matrix_text); + } + else if(text_dummy.at(LetterPos) == '+') + { + initArray(plus,5,matrix_text); + } + else if(text_dummy.at(LetterPos) == '-') + { + initArray(minus,3,matrix_text); + } + else if(text_dummy.at(LetterPos) == '=') + { + initArray(_equal,3,matrix_text); + } + else if(text_dummy.at(LetterPos) == ',') + { + initArray(comma,2,matrix_text); + } + else if(text_dummy.at(LetterPos) == '.') + { + initArray(point,1,matrix_text); + } + else if(text_dummy.at(LetterPos) == '/') + { + initArray(slash,5,matrix_text); + } + else if(text_dummy.at(LetterPos) == 58) + { + initArray(d_point,1,matrix_text); + } + else if(text_dummy.at(LetterPos) == 59) + { + initArray(poicom,2,matrix_text); + } + else if(text_dummy.at(LetterPos) == 95) + { + initArray(undlin,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == 92) + { + initArray(b_slash,5,matrix_text); + } + else if(text_dummy.at(LetterPos) == 64) + { + initArray(at,5,matrix_text); + } + else if(text_dummy.at(LetterPos) == 62) + { + initArray(more,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == 60) + { + initArray(less,1,matrix_text); + } + else if(text_dummy.at(LetterPos) == '[') + { + initArray(brack_o,2,matrix_text); + } + else if(text_dummy.at(LetterPos) == ']') + { + initArray(brack_c,2,matrix_text); + } + else if(text_dummy.at(LetterPos) == 94) + { + initArray(roof,3,matrix_text); + } + else if(text_dummy.at(LetterPos) == '{') + { + initArray(brace_o,3,matrix_text); + } + else if(text_dummy.at(LetterPos) == '}') + { + initArray(brace_c,3,matrix_text); + } + else if(text_dummy.at(LetterPos) == '~') + { + initArray(wave,4,matrix_text); + } + else if(text_dummy.at(LetterPos) == '|') + { + initArray(stick,1,matrix_text); + } + else if(text_dummy.at(LetterPos) == '`') + { + initArray(frapo,2,matrix_text); + } + else if(text_dummy.at(LetterPos) == ' ') + { + initArray(space,3,matrix_text); + } + } + c_frame += 3; +} \ No newline at end of file