![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
LED_MTX_TEST code
Dependencies: mbed
main.cpp@0:29b88eaced15, 2017-07-24 (annotated)
- Committer:
- GreenBear
- Date:
- Mon Jul 24 00:46:25 2017 +0000
- Revision:
- 0:29b88eaced15
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
GreenBear | 0:29b88eaced15 | 1 | #include "mbed.h" |
GreenBear | 0:29b88eaced15 | 2 | |
GreenBear | 0:29b88eaced15 | 3 | int thumb[8] = {\ |
GreenBear | 0:29b88eaced15 | 4 | 0b00100000,\ |
GreenBear | 0:29b88eaced15 | 5 | 0b01010000,\ |
GreenBear | 0:29b88eaced15 | 6 | 0b11111000,\ |
GreenBear | 0:29b88eaced15 | 7 | 0b10001000,\ |
GreenBear | 0:29b88eaced15 | 8 | 0b10001111,\ |
GreenBear | 0:29b88eaced15 | 9 | 0b00001000,\ |
GreenBear | 0:29b88eaced15 | 10 | 0b00001000,\ |
GreenBear | 0:29b88eaced15 | 11 | 0b00000111}; |
GreenBear | 0:29b88eaced15 | 12 | |
GreenBear | 0:29b88eaced15 | 13 | int fft_val[8] = {2,5,7,3,4,6,2.8};//random |
GreenBear | 0:29b88eaced15 | 14 | |
GreenBear | 0:29b88eaced15 | 15 | void bootup(); |
GreenBear | 0:29b88eaced15 | 16 | void led_line_char(int state); |
GreenBear | 0:29b88eaced15 | 17 | void led_line_graph(int state); |
GreenBear | 0:29b88eaced15 | 18 | void digitaIO(int pin, int val); |
GreenBear | 0:29b88eaced15 | 19 | |
GreenBear | 0:29b88eaced15 | 20 | int main() { |
GreenBear | 0:29b88eaced15 | 21 | bootup(); |
GreenBear | 0:29b88eaced15 | 22 | |
GreenBear | 0:29b88eaced15 | 23 | while(1){ |
GreenBear | 0:29b88eaced15 | 24 | for(int i =0 ;i<8;i++){ |
GreenBear | 0:29b88eaced15 | 25 | int y = 9+i; |
GreenBear | 0:29b88eaced15 | 26 | digitaIO(y,1); |
GreenBear | 0:29b88eaced15 | 27 | //led_line_char(thumb[i]); |
GreenBear | 0:29b88eaced15 | 28 | led_line_graph(fft_val[i]); |
GreenBear | 0:29b88eaced15 | 29 | wait(1.0/8.0/144.0); |
GreenBear | 0:29b88eaced15 | 30 | digitaIO(y,0); |
GreenBear | 0:29b88eaced15 | 31 | } |
GreenBear | 0:29b88eaced15 | 32 | } |
GreenBear | 0:29b88eaced15 | 33 | } |
GreenBear | 0:29b88eaced15 | 34 | |
GreenBear | 0:29b88eaced15 | 35 | void bootup(){ |
GreenBear | 0:29b88eaced15 | 36 | for(int i =1 ;i<=8;i++){ |
GreenBear | 0:29b88eaced15 | 37 | digitaIO(i,0); |
GreenBear | 0:29b88eaced15 | 38 | } |
GreenBear | 0:29b88eaced15 | 39 | for(int i =9 ;i<=16;i++){ |
GreenBear | 0:29b88eaced15 | 40 | digitaIO(i,1); |
GreenBear | 0:29b88eaced15 | 41 | } |
GreenBear | 0:29b88eaced15 | 42 | wait(.2); |
GreenBear | 0:29b88eaced15 | 43 | for(int i =1 ;i<=8;i++){ |
GreenBear | 0:29b88eaced15 | 44 | digitaIO(i,1); |
GreenBear | 0:29b88eaced15 | 45 | } |
GreenBear | 0:29b88eaced15 | 46 | wait(.2); |
GreenBear | 0:29b88eaced15 | 47 | for(int i =1 ;i<=16;i++){ |
GreenBear | 0:29b88eaced15 | 48 | digitaIO(i,0); |
GreenBear | 0:29b88eaced15 | 49 | } |
GreenBear | 0:29b88eaced15 | 50 | } |
GreenBear | 0:29b88eaced15 | 51 | |
GreenBear | 0:29b88eaced15 | 52 | void led_line_char(int state){ |
GreenBear | 0:29b88eaced15 | 53 | int a = state; |
GreenBear | 0:29b88eaced15 | 54 | int b = 1; |
GreenBear | 0:29b88eaced15 | 55 | for(int i = 0;i<8;i++){ |
GreenBear | 0:29b88eaced15 | 56 | int x = i+1;//8-i; |
GreenBear | 0:29b88eaced15 | 57 | b = a%2; |
GreenBear | 0:29b88eaced15 | 58 | digitaIO(x,!b); |
GreenBear | 0:29b88eaced15 | 59 | a = a/2; |
GreenBear | 0:29b88eaced15 | 60 | } |
GreenBear | 0:29b88eaced15 | 61 | } |
GreenBear | 0:29b88eaced15 | 62 | |
GreenBear | 0:29b88eaced15 | 63 | void led_line_graph(int state){ |
GreenBear | 0:29b88eaced15 | 64 | int a = state; |
GreenBear | 0:29b88eaced15 | 65 | for(int i = 0;i<8;i++){ |
GreenBear | 0:29b88eaced15 | 66 | int x = i+1;//8-i; |
GreenBear | 0:29b88eaced15 | 67 | if(i <= a){digitaIO(x,1);} |
GreenBear | 0:29b88eaced15 | 68 | else{digitaIO(x,0);} |
GreenBear | 0:29b88eaced15 | 69 | } |
GreenBear | 0:29b88eaced15 | 70 | } |
GreenBear | 0:29b88eaced15 | 71 | |
GreenBear | 0:29b88eaced15 | 72 | void digitaIO(int pin, int val){ |
GreenBear | 0:29b88eaced15 | 73 | switch (pin){ |
GreenBear | 0:29b88eaced15 | 74 | case 1 : { DigitalOut(D0,val); break;} |
GreenBear | 0:29b88eaced15 | 75 | case 2 : { DigitalOut(D1,val); break;} |
GreenBear | 0:29b88eaced15 | 76 | case 3 : { DigitalOut(D2,val); break;} |
GreenBear | 0:29b88eaced15 | 77 | case 4 : { DigitalOut(D3,val); break;} |
GreenBear | 0:29b88eaced15 | 78 | case 5 : { DigitalOut(D4,val); break;} |
GreenBear | 0:29b88eaced15 | 79 | case 6 : { DigitalOut(D5,val); break;} |
GreenBear | 0:29b88eaced15 | 80 | case 7 : { DigitalOut(D6,val); break;} |
GreenBear | 0:29b88eaced15 | 81 | case 8 : { DigitalOut(D7,val); break;} |
GreenBear | 0:29b88eaced15 | 82 | case 9 : { DigitalOut(D8,val); break;} |
GreenBear | 0:29b88eaced15 | 83 | case 10 : { DigitalOut(D9,val); break;} |
GreenBear | 0:29b88eaced15 | 84 | case 11 : { DigitalOut(D10,val); break;} |
GreenBear | 0:29b88eaced15 | 85 | case 12 : { DigitalOut(A5,val); break;} |
GreenBear | 0:29b88eaced15 | 86 | case 13 : { DigitalOut(D12,val); break;} |
GreenBear | 0:29b88eaced15 | 87 | case 14 : { DigitalOut(D13,val); break;} |
GreenBear | 0:29b88eaced15 | 88 | case 15 : { DigitalOut(D14,val); break;} |
GreenBear | 0:29b88eaced15 | 89 | case 16 : { DigitalOut(D15,val); break;} |
GreenBear | 0:29b88eaced15 | 90 | default : { break; } |
GreenBear | 0:29b88eaced15 | 91 | } |
GreenBear | 0:29b88eaced15 | 92 | } |