Projectlab Elektronica-ICT KULeuven

Dependencies:   EthernetInterface TMP102 TextLCD mbed-rtos mbed

werking.pdf

Committer:
seppeduwe
Date:
Sun Mar 16 16:52:27 2014 +0000
Revision:
2:1243006bb879
Parent:
1:635e76c52151
Child:
3:344115c04cd0
Einde opendeurdag

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 2:1243006bb879 33 Frame testFrame;
seppeduwe 1:635e76c52151 34 Server server("192.168.0.107");
seppeduwe 1:635e76c52151 35 server.printStatus();
seppeduwe 2:1243006bb879 36 Display display;
seppeduwe 2:1243006bb879 37 display.setText("Seppe's MBED");
seppeduwe 2:1243006bb879 38 Tune tune;
seppeduwe 1:635e76c52151 39 Temperature temp;
seppeduwe 2:1243006bb879 40 Potentiometer potentiometer;
seppeduwe 0:ae3af7d18c4a 41
seppeduwe 0:ae3af7d18c4a 42 while(1) {
seppeduwe 0:ae3af7d18c4a 43 if(server.read(buf)) {
seppeduwe 2:1243006bb879 44 if(!testFrame.Decode(buf))
seppeduwe 1:635e76c52151 45 printf("Frame CRC Error \n\r");
seppeduwe 2:1243006bb879 46 if(testFrame.getIdDestinationMbed()==7) {
seppeduwe 1:635e76c52151 47 printf("Voor mij\n\r");
seppeduwe 2:1243006bb879 48 PWMout=potentiometer.getPotentiometer()/100;
seppeduwe 2:1243006bb879 49 tune.play(testFrame.getTune());
seppeduwe 2:1243006bb879 50 //display.setText("Temp: %d",(0.026862*(testFrame.getTemperature()-25)));
seppeduwe 2:1243006bb879 51 display.setText("Temp: %d",testFrame.getTemperature());
seppeduwe 2:1243006bb879 52 testFrame.setIdDestinationMbed(IpDestination);
seppeduwe 2:1243006bb879 53 testFrame.setTemperature(temp.getTemperature());
seppeduwe 2:1243006bb879 54 testFrame.setPWMDutycycle(potentiometer.getPotentiometer());
seppeduwe 2:1243006bb879 55 testFrame.setTune(testFrame.getTune()+1);
seppeduwe 2:1243006bb879 56 testFrame.AddID(7);
seppeduwe 2:1243006bb879 57 testFrame.Encode(buf);
seppeduwe 1:635e76c52151 58 }
seppeduwe 2:1243006bb879 59 if(!testFrame.CheckMyID(7)) {
seppeduwe 1:635e76c52151 60 server.connect(destIp);
seppeduwe 1:635e76c52151 61 server.send(buf);
seppeduwe 1:635e76c52151 62 }
seppeduwe 0:ae3af7d18c4a 63 }
seppeduwe 1:635e76c52151 64 if(BoolIpDestination) {
seppeduwe 1:635e76c52151 65 if(IpDestination!=15)
seppeduwe 1:635e76c52151 66 IpDestination++;
seppeduwe 1:635e76c52151 67 else
seppeduwe 1:635e76c52151 68 IpDestination=1;
seppeduwe 1:635e76c52151 69 sprintf(destIp,"192.168.0.1%02i",IpDestination);
seppeduwe 2:1243006bb879 70 display.setText("192.168.0.1%02i",IpDestination);
seppeduwe 1:635e76c52151 71 BoolIpDestination=0;
seppeduwe 1:635e76c52151 72 wait(0.5);
seppeduwe 1:635e76c52151 73 }
seppeduwe 1:635e76c52151 74 if(Send) {
seppeduwe 2:1243006bb879 75 testFrame.setIdDestinationMbed(IpDestination);
seppeduwe 2:1243006bb879 76 testFrame.setTemperature(temp.getTemperature());
seppeduwe 2:1243006bb879 77 testFrame.setPWMDutycycle(potentiometer.getPotentiometer());
seppeduwe 2:1243006bb879 78 testFrame.setTune(1);
seppeduwe 2:1243006bb879 79 testFrame.AddID(7);
seppeduwe 1:635e76c52151 80 //char testIDs[]= {0x08,0x09,0x0A};
seppeduwe 1:635e76c52151 81 //testFrame->setLengthIDs(3);
seppeduwe 1:635e76c52151 82 //testFrame->setIDs(testIDs);
seppeduwe 2:1243006bb879 83 testFrame.Encode(buf);
seppeduwe 0:ae3af7d18c4a 84
seppeduwe 1:635e76c52151 85 server.connect(destIp);
seppeduwe 0:ae3af7d18c4a 86 server.send(buf);
seppeduwe 1:635e76c52151 87 Send=0;
seppeduwe 1:635e76c52151 88 wait(0.5);
seppeduwe 0:ae3af7d18c4a 89 }
seppeduwe 0:ae3af7d18c4a 90 }
seppeduwe 2:1243006bb879 91 }