![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
demo versie 16/05
Dependencies: EthernetInterface mbed-rto mbed
Fork of ProjectVLC by
LEDDriver.cpp@10:7871aeacea08, 2018-04-25 (annotated)
- Committer:
- albireo987
- Date:
- Wed Apr 25 07:22:18 2018 +0000
- Revision:
- 10:7871aeacea08
- Parent:
- 9:c800045806f0
- Child:
- 12:1dc7dfe499fd
- Child:
- 25:4c673da1a3ae
driver 7kHz
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
albireo987 | 2:36158325f7b0 | 1 | #include "LEDDriver.h" |
albireo987 | 9:c800045806f0 | 2 | Serial pc(USBTX,USBRX); |
albireo987 | 9:c800045806f0 | 3 | |
albireo987 | 10:7871aeacea08 | 4 | LEDDriver::LEDDriver( int* sharedDirections, int sizeOfSharedDirections) |
albireo987 | 2:36158325f7b0 | 5 | { |
albireo987 | 9:c800045806f0 | 6 | static int messageList[8]={0}; |
albireo987 | 10:7871aeacea08 | 7 | static DigitalOut leds[]={DigitalOut(p23),DigitalOut(p11),DigitalOut(p12),DigitalOut(p13),DigitalOut(p14),DigitalOut(p15),DigitalOut(p16),DigitalOut(p17)}; |
albireo987 | 2:36158325f7b0 | 8 | this->copy=Copy(); |
albireo987 | 2:36158325f7b0 | 9 | this->messageList=messageList; |
albireo987 | 2:36158325f7b0 | 10 | this->leds=leds; |
albireo987 | 9:c800045806f0 | 11 | copy.copyInt((directions),sharedDirections,sizeOfSharedDirections); |
albireo987 | 2:36158325f7b0 | 12 | } |
albireo987 | 2:36158325f7b0 | 13 | |
albireo987 | 10:7871aeacea08 | 14 | void LEDDriver::determineMessage(int directionValue,int led) |
albireo987 | 2:36158325f7b0 | 15 | { |
albireo987 | 9:c800045806f0 | 16 | if(directionValue==0) |
albireo987 | 9:c800045806f0 | 17 | { |
albireo987 | 9:c800045806f0 | 18 | messageList[led]=0; |
albireo987 | 9:c800045806f0 | 19 | } |
albireo987 | 9:c800045806f0 | 20 | else if(directionValue==1) |
albireo987 | 9:c800045806f0 | 21 | { |
albireo987 | 9:c800045806f0 | 22 | messageList[led]=1; |
albireo987 | 9:c800045806f0 | 23 | } |
albireo987 | 9:c800045806f0 | 24 | else if(directionValue==2) |
albireo987 | 9:c800045806f0 | 25 | { |
albireo987 | 9:c800045806f0 | 26 | messageList[led]=2; |
albireo987 | 9:c800045806f0 | 27 | } |
albireo987 | 9:c800045806f0 | 28 | else if(directionValue==3) |
albireo987 | 9:c800045806f0 | 29 | { |
albireo987 | 9:c800045806f0 | 30 | messageList[led]=3; |
albireo987 | 9:c800045806f0 | 31 | } |
albireo987 | 2:36158325f7b0 | 32 | } |
albireo987 | 2:36158325f7b0 | 33 | |
albireo987 | 2:36158325f7b0 | 34 | int LEDDriver::getDirection(int id) |
albireo987 | 2:36158325f7b0 | 35 | { |
albireo987 | 9:c800045806f0 | 36 | int direction= directions[id]; |
albireo987 | 2:36158325f7b0 | 37 | return direction; |
albireo987 | 2:36158325f7b0 | 38 | } |
albireo987 | 2:36158325f7b0 | 39 | |
albireo987 | 2:36158325f7b0 | 40 | void LEDDriver::drive(int numberOfLeds) |
albireo987 | 2:36158325f7b0 | 41 | { |
albireo987 | 9:c800045806f0 | 42 | encodeAll(numberOfLeds);// 1 1 1 1 0 0 0 0 0 1 |
albireo987 | 10:7871aeacea08 | 43 | static int codedMessage0[]={1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0};//{1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,1,0}; currently frequency measure message(standard square wave) |
albireo987 | 9:c800045806f0 | 44 | // 1 1 1 1 0 1 0 0 0 1 |
albireo987 | 9:c800045806f0 | 45 | static int codedMessage1[]={1,0,1,0,1,0,1,0,0,1,1,0,0,1,0,1,0,1,1,0}; |
albireo987 | 9:c800045806f0 | 46 | // 1 1 1 1 1 0 1 0 0 1 |
albireo987 | 9:c800045806f0 | 47 | static int codedMessage2[]={1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,1,0}; |
albireo987 | 9:c800045806f0 | 48 | // 1 1 1 1 1 1 0 0 0 1 |
albireo987 | 9:c800045806f0 | 49 | static int codedMessage3[]={1,0,1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,1,0}; |
albireo987 | 10:7871aeacea08 | 50 | while(true) |
albireo987 | 2:36158325f7b0 | 51 | { |
albireo987 | 9:c800045806f0 | 52 | for(int j=0;j<20;j++) |
albireo987 | 9:c800045806f0 | 53 | { |
albireo987 | 9:c800045806f0 | 54 | for(int i =0;i<numberOfLeds;i++) |
albireo987 | 9:c800045806f0 | 55 | { |
albireo987 | 9:c800045806f0 | 56 | if(messageList[i]==0) |
albireo987 | 9:c800045806f0 | 57 | { |
albireo987 | 9:c800045806f0 | 58 | leds[i].write(codedMessage0[j]); |
albireo987 | 10:7871aeacea08 | 59 | ownWait(10);//100=708 HZ 10 = 7.08 kHZ |
albireo987 | 10:7871aeacea08 | 60 | } |
albireo987 | 9:c800045806f0 | 61 | else if(messageList[i]==1) |
albireo987 | 9:c800045806f0 | 62 | { |
albireo987 | 9:c800045806f0 | 63 | leds[i].write(codedMessage1[j]); |
albireo987 | 10:7871aeacea08 | 64 | ownWait(10); |
albireo987 | 9:c800045806f0 | 65 | } |
albireo987 | 9:c800045806f0 | 66 | else if(messageList[i]==2) |
albireo987 | 9:c800045806f0 | 67 | { |
albireo987 | 9:c800045806f0 | 68 | leds[i].write(codedMessage2[j]); |
albireo987 | 10:7871aeacea08 | 69 | ownWait(10); |
albireo987 | 9:c800045806f0 | 70 | } |
albireo987 | 9:c800045806f0 | 71 | else if(messageList[i]==3) |
albireo987 | 9:c800045806f0 | 72 | { |
albireo987 | 9:c800045806f0 | 73 | leds[i].write(codedMessage3[j]); |
albireo987 | 10:7871aeacea08 | 74 | ownWait(10); |
albireo987 | 9:c800045806f0 | 75 | } |
albireo987 | 9:c800045806f0 | 76 | } |
albireo987 | 9:c800045806f0 | 77 | } |
albireo987 | 9:c800045806f0 | 78 | } |
albireo987 | 2:36158325f7b0 | 79 | } |
albireo987 | 2:36158325f7b0 | 80 | |
albireo987 | 2:36158325f7b0 | 81 | void LEDDriver::run(int numberOfLeds) |
albireo987 | 2:36158325f7b0 | 82 | { |
albireo987 | 2:36158325f7b0 | 83 | drive(numberOfLeds); |
albireo987 | 2:36158325f7b0 | 84 | } |
albireo987 | 2:36158325f7b0 | 85 | |
albireo987 | 2:36158325f7b0 | 86 | void LEDDriver::encodeAll(int numberOfLeds) |
albireo987 | 2:36158325f7b0 | 87 | { |
albireo987 | 2:36158325f7b0 | 88 | for(int i = 0;i<numberOfLeds;i++) |
albireo987 | 2:36158325f7b0 | 89 | { |
albireo987 | 10:7871aeacea08 | 90 | determineMessage(getDirection(i),i); |
albireo987 | 2:36158325f7b0 | 91 | } |
albireo987 | 10:7871aeacea08 | 92 | } |
albireo987 | 10:7871aeacea08 | 93 | |
albireo987 | 10:7871aeacea08 | 94 | void LEDDriver::ownWait(uint32_t us) |
albireo987 | 10:7871aeacea08 | 95 | { |
albireo987 | 10:7871aeacea08 | 96 | for(uint32_t i=0;i<us;i++) |
albireo987 | 10:7871aeacea08 | 97 | { |
albireo987 | 10:7871aeacea08 | 98 | for(volatile uint32_t j =0; j <96;j++) |
albireo987 | 10:7871aeacea08 | 99 | { |
albireo987 | 10:7871aeacea08 | 100 | |
albireo987 | 10:7871aeacea08 | 101 | } |
albireo987 | 10:7871aeacea08 | 102 | } |
albireo987 | 2:36158325f7b0 | 103 | } |