demo versie 16/05

Dependencies:   EthernetInterface mbed-rto mbed

Fork of ProjectVLC by Klaas Govaerts

Committer:
albireo987
Date:
Wed Apr 18 10:06:48 2018 +0000
Revision:
9:c800045806f0
Parent:
8:a987e04734dd
Child:
10:7871aeacea08
driver working delay needs finetuning;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
albireo987 2:36158325f7b0 1 #include "LEDDriver.h"
albireo987 9:c800045806f0 2 Serial pc(USBTX,USBRX);
albireo987 9:c800045806f0 3
albireo987 9:c800045806f0 4 LEDDriver::LEDDriver(/*Mutex* lock,*/ int* sharedDirections, int sizeOfSharedDirections)
albireo987 2:36158325f7b0 5 {
albireo987 9:c800045806f0 6 static int messageList[8]={0};
albireo987 9:c800045806f0 7 static DigitalOut leds[]={DigitalOut(p10),DigitalOut(p11),DigitalOut(p12),DigitalOut(p13),DigitalOut(p14),DigitalOut(p15),DigitalOut(p16),DigitalOut(p17)};
albireo987 2:36158325f7b0 8 //this->lock=lock;
albireo987 2:36158325f7b0 9 this->copy=Copy();
albireo987 2:36158325f7b0 10 this->messageList=messageList;
albireo987 2:36158325f7b0 11 this->leds=leds;
albireo987 9:c800045806f0 12 copy.copyInt((directions),sharedDirections,sizeOfSharedDirections);
albireo987 2:36158325f7b0 13 }
albireo987 2:36158325f7b0 14
albireo987 2:36158325f7b0 15 void LEDDriver::encode(int directionValue,int led)
albireo987 2:36158325f7b0 16 {
albireo987 9:c800045806f0 17 if(directionValue==0)
albireo987 9:c800045806f0 18 {
albireo987 9:c800045806f0 19 messageList[led]=0;
albireo987 9:c800045806f0 20 }
albireo987 9:c800045806f0 21 else if(directionValue==1)
albireo987 9:c800045806f0 22 {
albireo987 9:c800045806f0 23 messageList[led]=1;
albireo987 9:c800045806f0 24 }
albireo987 9:c800045806f0 25 else if(directionValue==2)
albireo987 9:c800045806f0 26 {
albireo987 9:c800045806f0 27 messageList[led]=2;
albireo987 9:c800045806f0 28 }
albireo987 9:c800045806f0 29 else if(directionValue==3)
albireo987 9:c800045806f0 30 {
albireo987 9:c800045806f0 31 messageList[led]=3;
albireo987 9:c800045806f0 32 }
albireo987 2:36158325f7b0 33 }
albireo987 2:36158325f7b0 34
albireo987 2:36158325f7b0 35 int LEDDriver::getDirection(int id)
albireo987 2:36158325f7b0 36 {
albireo987 9:c800045806f0 37 int direction= directions[id];
albireo987 2:36158325f7b0 38 return direction;
albireo987 2:36158325f7b0 39 }
albireo987 2:36158325f7b0 40
albireo987 2:36158325f7b0 41 void LEDDriver::drive(int numberOfLeds)
albireo987 2:36158325f7b0 42 {
albireo987 9:c800045806f0 43 int delay = 25;
albireo987 9:c800045806f0 44 encodeAll(numberOfLeds);// 1 1 1 1 0 0 0 0 0 1
albireo987 9:c800045806f0 45 static int codedMessage0[]={1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,1,0};
albireo987 9:c800045806f0 46 // 1 1 1 1 0 1 0 0 0 1
albireo987 9:c800045806f0 47 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 48 // 1 1 1 1 1 0 1 0 0 1
albireo987 9:c800045806f0 49 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 50 // 1 1 1 1 1 1 0 0 0 1
albireo987 9:c800045806f0 51 static int codedMessage3[]={1,0,1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,1,0};
albireo987 9:c800045806f0 52 while(true)
albireo987 2:36158325f7b0 53 {
albireo987 9:c800045806f0 54 for(int j=0;j<20;j++)
albireo987 9:c800045806f0 55 {
albireo987 9:c800045806f0 56 for(int i =0;i<numberOfLeds;i++)
albireo987 9:c800045806f0 57 {
albireo987 9:c800045806f0 58 if(messageList[i]==0)
albireo987 9:c800045806f0 59 {
albireo987 9:c800045806f0 60 leds[i].write(codedMessage0[j]);
albireo987 9:c800045806f0 61 pc.printf("led%d,message%d:%d\n\r",i,j,codedMessage0[j]);
albireo987 9:c800045806f0 62 wait_ms(delay);//500Hz 1/500 gewenste periode 8/90MHz(#leds/fclock) basis periode dus verhouding van de perioden / Clock is uiteindelijke frequentie (grof) moet manueel
albireo987 9:c800045806f0 63 } // gefinetuned worden.
albireo987 9:c800045806f0 64 else if(messageList[i]==1)
albireo987 9:c800045806f0 65 {
albireo987 9:c800045806f0 66 leds[i].write(codedMessage1[j]);
albireo987 9:c800045806f0 67 pc.printf("led%d,message%d:%d\n\r",i,j,codedMessage1[j]);
albireo987 9:c800045806f0 68 wait_ms(delay);
albireo987 9:c800045806f0 69 }
albireo987 9:c800045806f0 70 else if(messageList[i]==2)
albireo987 9:c800045806f0 71 {
albireo987 9:c800045806f0 72 leds[i].write(codedMessage2[j]);
albireo987 9:c800045806f0 73 pc.printf("led%d,message%d:%d\n\r",i,j,codedMessage2[j]);
albireo987 9:c800045806f0 74 wait_ms(delay);
albireo987 9:c800045806f0 75 }
albireo987 9:c800045806f0 76 else if(messageList[i]==3)
albireo987 9:c800045806f0 77 {
albireo987 9:c800045806f0 78 leds[i].write(codedMessage3[j]);
albireo987 9:c800045806f0 79 pc.printf("led%d,message%d:%d\n\r",i,j,codedMessage3[j]);
albireo987 9:c800045806f0 80 wait_ms(delay);
albireo987 9:c800045806f0 81 }
albireo987 9:c800045806f0 82 }
albireo987 9:c800045806f0 83 }
albireo987 9:c800045806f0 84 }
albireo987 2:36158325f7b0 85 }
albireo987 2:36158325f7b0 86
albireo987 2:36158325f7b0 87 void LEDDriver::run(int numberOfLeds)
albireo987 2:36158325f7b0 88 {
albireo987 2:36158325f7b0 89 drive(numberOfLeds);
albireo987 2:36158325f7b0 90 }
albireo987 2:36158325f7b0 91
albireo987 2:36158325f7b0 92 void LEDDriver::encodeAll(int numberOfLeds)
albireo987 2:36158325f7b0 93 {
albireo987 2:36158325f7b0 94 for(int i = 0;i<numberOfLeds;i++)
albireo987 2:36158325f7b0 95 {
albireo987 2:36158325f7b0 96 encode(getDirection(i),i);
albireo987 2:36158325f7b0 97 }
albireo987 2:36158325f7b0 98 }