Projectlab Elektronica-ICT KULeuven

Dependencies:   EthernetInterface TMP102 TextLCD mbed-rtos mbed

werking.pdf

Committer:
seppeduwe
Date:
Sun Mar 16 15:08:10 2014 +0000
Revision:
1:635e76c52151
Parent:
0:ae3af7d18c4a
Child:
2:1243006bb879
Main goed

Who changed what in which revision?

UserRevisionLine numberNew contents of line
seppeduwe 0:ae3af7d18c4a 1 #include "mbed.h"
seppeduwe 1:635e76c52151 2 #include "Server.h"
seppeduwe 0:ae3af7d18c4a 3 #include "Frame.h"
seppeduwe 0:ae3af7d18c4a 4 #include "Tune.h"
seppeduwe 0:ae3af7d18c4a 5 #include "Display.h"
seppeduwe 1:635e76c52151 6 #include "Temperature.h"
seppeduwe 1:635e76c52151 7 #include "Potentiometer.h"
seppeduwe 0:ae3af7d18c4a 8
seppeduwe 1:635e76c52151 9 InterruptIn buttonSend(p8);
seppeduwe 1:635e76c52151 10 bool Send;
seppeduwe 1:635e76c52151 11 void SendISR()
seppeduwe 0:ae3af7d18c4a 12 {
seppeduwe 1:635e76c52151 13 Send=1;
seppeduwe 0:ae3af7d18c4a 14 }
seppeduwe 0:ae3af7d18c4a 15
seppeduwe 1:635e76c52151 16 InterruptIn buttonDestinationIpUp(p7);
seppeduwe 1:635e76c52151 17 int IpDestination=10;
seppeduwe 1:635e76c52151 18 bool BoolIpDestination;
seppeduwe 1:635e76c52151 19 char destIp[14];
seppeduwe 1:635e76c52151 20 void DestinationIpUp()
seppeduwe 1:635e76c52151 21 {
seppeduwe 1:635e76c52151 22 BoolIpDestination=1;
seppeduwe 1:635e76c52151 23 }
seppeduwe 1:635e76c52151 24
seppeduwe 1:635e76c52151 25 //PWM-signaal gegenereerd op basis van de potentiometerwaarde
seppeduwe 1:635e76c52151 26 PwmOut PWMout(p22);
seppeduwe 0:ae3af7d18c4a 27 int main()
seppeduwe 0:ae3af7d18c4a 28 {
seppeduwe 1:635e76c52151 29 buttonSend.rise(&SendISR); // attach the address of the flip function to the rising edge
seppeduwe 1:635e76c52151 30 buttonDestinationIpUp.rise(&DestinationIpUp); // attach the address of the flip function to the rising edge
seppeduwe 0:ae3af7d18c4a 31
seppeduwe 1:635e76c52151 32 char buf[256];
seppeduwe 1:635e76c52151 33 Frame* testFrame = new Frame();
seppeduwe 1:635e76c52151 34 Server server("192.168.0.107");
seppeduwe 1:635e76c52151 35 server.printStatus();
seppeduwe 1:635e76c52151 36 Display* display=new Display();
seppeduwe 1:635e76c52151 37 display->setText("Seppe's MBED");
seppeduwe 1:635e76c52151 38 Tune* tune = new Tune();
seppeduwe 1:635e76c52151 39 Temperature temp;
seppeduwe 1:635e76c52151 40 Potentiometer* potentiometer = new Potentiometer();
seppeduwe 0:ae3af7d18c4a 41
seppeduwe 0:ae3af7d18c4a 42 while(1) {
seppeduwe 0:ae3af7d18c4a 43 if(server.read(buf)) {
seppeduwe 1:635e76c52151 44 if(!testFrame->Decode(buf))
seppeduwe 1:635e76c52151 45 printf("Frame CRC Error \n\r");
seppeduwe 1:635e76c52151 46 if(testFrame->getIdDestinationMbed()==7) {
seppeduwe 1:635e76c52151 47 printf("Voor mij\n\r");
seppeduwe 1:635e76c52151 48 PWMout=potentiometer->getPotentiometer()/100;
seppeduwe 1:635e76c52151 49 tune->play(testFrame->getTune());
seppeduwe 1:635e76c52151 50 display->setText("Temp: %d",testFrame->getTemperature());
seppeduwe 1:635e76c52151 51 testFrame->setIdDestinationMbed(IpDestination);
seppeduwe 1:635e76c52151 52 testFrame->setTemperature(temp.getTemperature());
seppeduwe 1:635e76c52151 53 testFrame->setPWMDutycycle(potentiometer->getPotentiometer());
seppeduwe 1:635e76c52151 54 testFrame->setTune(testFrame->getTune()+1);
seppeduwe 1:635e76c52151 55 testFrame->AddID(7);
seppeduwe 1:635e76c52151 56 testFrame->Encode(buf);
seppeduwe 1:635e76c52151 57 }
seppeduwe 1:635e76c52151 58 if(!testFrame->CheckMyID(7)) {
seppeduwe 1:635e76c52151 59 server.connect(destIp);
seppeduwe 1:635e76c52151 60 server.send(buf);
seppeduwe 1:635e76c52151 61 }
seppeduwe 0:ae3af7d18c4a 62 }
seppeduwe 1:635e76c52151 63 if(BoolIpDestination) {
seppeduwe 1:635e76c52151 64 if(IpDestination!=15)
seppeduwe 1:635e76c52151 65 IpDestination++;
seppeduwe 1:635e76c52151 66 else
seppeduwe 1:635e76c52151 67 IpDestination=1;
seppeduwe 1:635e76c52151 68 sprintf(destIp,"192.168.0.1%02i",IpDestination);
seppeduwe 1:635e76c52151 69 display->setText("192.168.0.1%02i",IpDestination);
seppeduwe 1:635e76c52151 70 BoolIpDestination=0;
seppeduwe 1:635e76c52151 71 wait(0.5);
seppeduwe 1:635e76c52151 72 }
seppeduwe 1:635e76c52151 73 if(Send) {
seppeduwe 1:635e76c52151 74 testFrame->setIdDestinationMbed(IpDestination);
seppeduwe 1:635e76c52151 75 testFrame->setTemperature(temp.getTemperature());
seppeduwe 1:635e76c52151 76 testFrame->setPWMDutycycle(potentiometer->getPotentiometer());
seppeduwe 1:635e76c52151 77 testFrame->setTune(1);
seppeduwe 1:635e76c52151 78 testFrame->AddID(7);
seppeduwe 1:635e76c52151 79 //char testIDs[]= {0x08,0x09,0x0A};
seppeduwe 1:635e76c52151 80 //testFrame->setLengthIDs(3);
seppeduwe 1:635e76c52151 81 //testFrame->setIDs(testIDs);
seppeduwe 1:635e76c52151 82 testFrame->Encode(buf);
seppeduwe 0:ae3af7d18c4a 83
seppeduwe 1:635e76c52151 84 server.connect(destIp);
seppeduwe 0:ae3af7d18c4a 85 server.send(buf);
seppeduwe 1:635e76c52151 86 Send=0;
seppeduwe 1:635e76c52151 87 wait(0.5);
seppeduwe 0:ae3af7d18c4a 88 }
seppeduwe 0:ae3af7d18c4a 89 }
seppeduwe 0:ae3af7d18c4a 90 }