Blue LED matrix (8x16) program. Gets text string through bluetooth and displays it on led matrix. Also has a clock function- get system time from a phone through bluetooth and enters clock mode. In clock mode it acts as a clock showing hours and minutes and blinking led every second. Clock mode can be broken if a text string is received through bluetooth.
Dependencies: mbed
Revision 0:06ac39308380, committed 2014-04-07
- Comitter:
- DaniusKalv
- Date:
- Mon Apr 07 18:41:42 2014 +0000
- Child:
- 1:13c8ce9188f1
- Commit message:
- ko
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Apr 07 18:41:42 2014 +0000 @@ -0,0 +1,6 @@ +#include "mbed.h" +#include "matrix.h" + +int main() { + matrix("LABAS LAURI"); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/matrix.cpp Mon Apr 07 18:41:42 2014 +0000 @@ -0,0 +1,460 @@ +#include "mbed.h" +#include <string> + +DigitalOut in3(p11); +DigitalOut in2(p12); +DigitalOut in1(p13); +DigitalOut clr1(p14); +DigitalOut clr(p15); +DigitalOut clk1(p16); +DigitalOut clk(p17); + +Serial pcc(USBTX, USBRX); + +int show[8][16] = {0}; +int z = 0; +int temp[8][5]; +int speed, length; +string get; +char take; +void letter(); +void letters(); +void stop(); +void display(long int *a[8]); +void screen(); +void clear(); +void see(); +void matrix(string o) {get = o; letter();} + +void letter(){ + //pcc.printf("\r\nLetter gets: %s", get); + length = get.length(); + //pcc.printf("\r\nString length= %i\r\n", length); + const size_t N = (length * 5) + 16; // the dimension of the matrix + long int** matrixx = new long int*[N]; // each element is a pointer to an array. + for(size_t i = 0; i < N; ++i) matrixx[i] = new long int[N]; // build rows + for(size_t i = 0; i < 8; ++i){ + for(size_t j = 0; j < N; ++j){ + matrixx[i][j] = 0; + } + } + for (int i = 0; i < length; i++){ + int j = 5 * i; + int k = j + 5; + int h, ii, g, xx; + take = get.at(i); + letters(); + for (h = j + 16, ii = 0; h < k + 16; h++, ii++){ + for (g = 0, xx = 0; g < 8; g++, xx++){ + //pcc.printf("G= %i H= %i XX= %i II= %i\r\n", g, h, xx, ii); + matrixx[g][h] = temp[xx][ii]; + } + } + /*for (int i = 0; i < 8; i++){ + for (int j = 0; j < ((length * 5) + 16) ; j++){ + pcc.printf("%i ", matrixx[i][j]); + } + pcc.printf("\r\n"); + } + pcc.printf("\r\n");*/ + } + display(matrixx); +} + +void letters(){ + pcc.printf("\r\nChar got: %c\r\n", take); + switch (take){ + case 'A': + pcc.printf("In a\r\n"); + int a[8][5] = { + {0, 1, 1, 0, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 1, 1, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + }; + memcpy(temp, a, sizeof(a)); + break; + case 'B': + //pcc.printf("In b\r\n"); + int b[8][5] = { + {1, 1, 1, 0, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 1, 1, 0, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 1, 1, 0, 0}, + }; + memcpy(temp, b, sizeof(b)); + break; + case 'C': + int c[8][5] = { + {0, 1, 1, 0, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 0, 0, 0}, + {1, 0, 0, 0, 0}, + {1, 0, 0, 0, 0}, + {1, 0, 0, 0, 0}, + {1, 0, 0, 1, 0}, + {0, 1, 1, 0, 0}, + }; + memcpy(temp, c, sizeof(c)); + break; + case 'D': + int d[8][5] = { + {1, 1, 1, 0, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 1, 1, 0, 0}, + }; + memcpy(temp, d, sizeof(d)); + break; + case 'E': + int e[8][5] = { + {1, 1, 1, 1, 0}, + {1, 0, 0, 0, 0}, + {1, 0, 0, 0, 0}, + {1, 0, 0, 0, 0}, + {1, 1, 1, 1, 0}, + {1, 0, 0, 0, 0}, + {1, 0, 0, 0, 0}, + {1, 1, 1, 1, 0}, + }; + memcpy(temp, e, sizeof(e)); + break; + case 'F': + int f[8][5] = { + {1, 1, 1, 1, 0}, + {1, 0, 0, 0, 0}, + {1, 0, 0, 0, 0}, + {1, 1, 1, 1, 0}, + {1, 0, 0, 0, 0}, + {1, 0, 0, 0, 0}, + {1, 0, 0, 0, 0}, + {1, 0, 0, 0, 0}, + }; + memcpy(temp, f, sizeof(f)); + break; + case 'G': + int g[8][5] = { + {0, 1, 1, 1, 0}, + {1, 0, 0, 0, 0}, + {1, 0, 0, 0, 0}, + {1, 0, 0, 0, 0}, + {1, 0, 1, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + {0, 1, 1, 0, 0}, + }; + memcpy(temp, g, sizeof(g)); + break; + case 'H': + int h[8][5] = { + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 1, 1, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + }; + memcpy(temp, h, sizeof(h)); + break; + case 'I': + int i[8][5] = { + {0, 1, 0, 0, 0}, + {0, 1, 0, 0, 0}, + {0, 1, 0, 0, 0}, + {0, 1, 0, 0, 0}, + {0, 1, 0, 0, 0}, + {0, 1, 0, 0, 0}, + {0, 1, 0, 0, 0}, + {0, 1, 0, 0, 0}, + }; + memcpy(temp, i, sizeof(i)); + break; + case 'J': + int j[8][5] = { + {0, 0, 0, 1, 0}, + {0, 0, 0, 1, 0}, + {0, 0, 0, 1, 0}, + {0, 0, 0, 1, 0}, + {0, 0, 0, 1, 0}, + {0, 0, 0, 1, 0}, + {0, 1, 0, 1, 0}, + {0, 0, 1, 0, 0}, + }; + memcpy(temp, j, sizeof(j)); + break; + case 'K': + int k[8][5] = { + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 1, 0, 0}, + {1, 0, 1, 0, 0}, + {1, 1, 0, 0, 0}, + {1, 0, 1, 0, 0}, + {1, 0, 1, 0, 0}, + {1, 0, 0, 1, 0}, + }; + memcpy(temp, k, sizeof(k)); + break; + case 'L': + //pcc.printf("In l\r\n"); + int l[8][5] = { + {1, 0, 0, 0, 0}, + {1, 0, 0, 0, 0}, + {1, 0, 0, 0, 0}, + {1, 0, 0, 0, 0}, + {1, 0, 0, 0, 0}, + {1, 0, 0, 0, 0}, + {1, 0, 0, 0, 0}, + {1, 1, 1, 1, 0}, + }; + memcpy(temp, l, sizeof(l)); + break; + case 'M': + int m[8][5] = { + {1, 0, 0, 0, 1}, + {1, 1, 0, 1, 1}, + {1, 0, 1, 0, 1}, + {1, 0, 0, 0, 1}, + {1, 0, 0, 0, 1}, + {1, 0, 0, 0, 1}, + {1, 0, 0, 0, 1}, + {1, 0, 0, 0, 1}, + }; + memcpy(temp, m, sizeof(m)); + break; + case 'N': + int n[8][5] = { + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 1, 0, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 1, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + }; + memcpy(temp, n, sizeof(n)); + break; + case 'O': + int o[8][5] = { + {1, 1, 1, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 1, 1, 1, 0}, + }; + memcpy(temp, o, sizeof(o)); + break; + case 'P': + int p[8][5] = { + {1, 1, 1, 0, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 1, 1, 0, 0}, + {1, 0, 0, 0, 0}, + {1, 0, 0, 0, 0}, + {1, 0, 0, 0, 0}, + {1, 0, 0, 0, 0}, + }; + memcpy(temp, p, sizeof(p)); + break; + case 'R': + int r[8][5] = { + {1, 1, 1, 0, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 1, 1, 0, 0}, + {1, 0, 1, 0, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + }; + memcpy(temp, r, sizeof(r)); + break; + case 'S': + int s[8][5] = { + {0, 1, 1, 1, 0}, + {1, 0, 0, 0, 0}, + {1, 0, 0, 0, 0}, + {0, 1, 1, 0, 0}, + {0, 0, 0, 1, 0}, + {0, 0, 0, 1, 0}, + {0, 0, 0, 1, 0}, + {1, 1, 1, 0, 0}, + }; + memcpy(temp, s, sizeof(s)); + break; + case 'T': + int t[8][5] = { + {1, 1, 1, 1, 1}, + {0, 0, 1, 0, 0}, + {0, 0, 1, 0, 0}, + {0, 0, 1, 0, 0}, + {0, 0, 1, 0, 0}, + {0, 0, 1, 0, 0}, + {0, 0, 1, 0, 0}, + {0, 0, 1, 0, 0}, + }; + memcpy(temp, t, sizeof(t)); + break; + case 'U': + int u[8][5] = { + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + {1, 0, 0, 1, 0}, + {0, 1, 1, 0, 0}, + }; + memcpy(temp, u, sizeof(u)); + break; + case 'V': + int v[8][5] = { + {1, 0, 0, 0, 1}, + {1, 0, 0, 0, 1}, + {1, 0, 0, 0, 1}, + {1, 0, 0, 0, 1}, + {1, 0, 0, 0, 1}, + {0, 1, 0, 1, 0}, + {0, 1, 0, 1, 0}, + {0, 0, 1, 0, 0}, + }; + memcpy(temp, v, sizeof(v)); + break; + case 'Z': + int z[8][5] = { + {1, 1, 1, 1, 0}, + {0, 0, 0, 1, 0}, + {0, 0, 1, 0, 0}, + {0, 0, 1, 0, 0}, + {0, 1, 0, 0, 0}, + {0, 1, 0, 0, 0}, + {1, 0, 0, 0, 0}, + {1, 1, 1, 1, 0}, + }; + memcpy(temp, z, sizeof(z)); + break; + case ' ': + int gap[8][5] = { + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + }; + memcpy(temp, gap, sizeof(gap)); + break; + default : + int def[8][5] = { + {0, 0, 1, 0, 0}, + {0, 0, 1, 0, 0}, + {0, 0, 1, 0, 0}, + {0, 0, 1, 0, 0}, + {0, 0, 1, 0, 0}, + {0, 0, 1, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 1, 0, 0}, + }; + memcpy(temp, def, sizeof(def)); + } +} + +void display(long int *a[8]){ + int ok = 0; + int trup[8] = {0}; + while(1){ + screen(); + z = z + 1; + if (z > 10){ + //pcc.printf("\r\n%i", z); + ok = ok + 1; + z = 0; + for (int jk = 0; jk < 8; jk++){ + trup[jk] = a[jk][0]; + } + for (int kj = 0; kj < ((length * 5) + 15); kj++){ + for (int jk = 0; jk < 8; jk++){ + a[jk][kj] = a[jk][kj + 1]; + } + } + for (int jk = 0; jk < 8; jk++){ + a[jk][(length * 5) + 15] = trup[jk]; + } + for (int kj = 0; kj < 16; kj++){ + for (int jk = 0; jk < 8; jk++){ + show[jk][kj] = a[jk][kj]; + } + } + //see(); + } + } +} + +void screen(){ + int a[8] = {0, 1, 1, 1, 1, 1, 1, 1}; + clear(); + for (int i = 0; i < 8; i++){ + clear(); + for (int g = 0; g < 8; g++){ + in1 = a[g]; + //pcc.printf("%i", a[g]); + clk = 1; + clk = 0; + } + //pcc.printf("\r\n"); + for (int j = 7; j > (-1); j--){ + in3 = show[i][j]; + in2 = show[i][j + 8]; + clk1 = 1; + clk1 = 0; + } + wait(0.001); + //pcc.printf("\r\n"); + a[i] = 1; + a[i + 1] = 0; + } +} + +void clear(){ + in1 = 1; + in2 = 0; + in3 = 0; + clk = 0; + clk1 = 0; + clr = 0; + clr1 = 0; + clr = 1; + clr1 = 1; +} + +void see(){ + for (int i = 0; i < 8; i++){ + for (int j = 0; j < 16 ; j++){ + pcc.printf("%i ", show[i][j]); + } + pcc.printf("\r\n"); + } + pcc.printf("\r\n"); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/matrix.h Mon Apr 07 18:41:42 2014 +0000 @@ -0,0 +1,7 @@ +#include <string> +#ifndef MATRIX_H_ +#define MATRIX_H_ + +void matrix(string get); + +#endif /* matrix_H_ */ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Apr 07 18:41:42 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f \ No newline at end of file