Projectlab Elektronica-ICT KULeuven

Dependencies:   EthernetInterface TMP102 TextLCD mbed-rtos mbed

werking.pdf

Committer:
seppeduwe
Date:
Mon Mar 17 18:40:46 2014 +0000
Revision:
4:466d859bfb13
Parent:
3:344115c04cd0
Einde Labo

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 3:344115c04cd0 33 Frame dataFrame;
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 3:344115c04cd0 44 if(!dataFrame.Decode(buf))
seppeduwe 1:635e76c52151 45 printf("Frame CRC Error \n\r");
seppeduwe 4:466d859bfb13 46 if((dataFrame.getIdDestinationMbed()==7) && (!dataFrame.CheckMyID(7))) {
seppeduwe 1:635e76c52151 47 printf("Voor mij\n\r");
seppeduwe 3:344115c04cd0 48 PWMout=potentiometer.getPotentiometer();
seppeduwe 3:344115c04cd0 49 PWMout.period(0.010);// set PWM period to 10 ms
seppeduwe 3:344115c04cd0 50 tune.play(dataFrame.getTune());
seppeduwe 4:466d859bfb13 51 display.setText("Temp: %d C",dataFrame.getTemperature());
seppeduwe 3:344115c04cd0 52 dataFrame.setIdDestinationMbed(IpDestination);
seppeduwe 3:344115c04cd0 53 dataFrame.setTemperature(temp.getTemperature());
seppeduwe 3:344115c04cd0 54 dataFrame.setPWMDutycycle(potentiometer.getPotentiometer());
seppeduwe 3:344115c04cd0 55 dataFrame.setTune(dataFrame.getTune()+1);
seppeduwe 3:344115c04cd0 56 dataFrame.AddID(7);
seppeduwe 3:344115c04cd0 57 dataFrame.Encode(buf);
seppeduwe 1:635e76c52151 58 server.connect(destIp);
seppeduwe 1:635e76c52151 59 server.send(buf);
seppeduwe 1:635e76c52151 60 }
seppeduwe 4:466d859bfb13 61 /* if() {
seppeduwe 4:466d859bfb13 62 server.connect(destIp);
seppeduwe 4:466d859bfb13 63 server.send(buf);
seppeduwe 4:466d859bfb13 64 }*/
seppeduwe 0:ae3af7d18c4a 65 }
seppeduwe 1:635e76c52151 66 if(BoolIpDestination) {
seppeduwe 1:635e76c52151 67 if(IpDestination!=15)
seppeduwe 1:635e76c52151 68 IpDestination++;
seppeduwe 1:635e76c52151 69 else
seppeduwe 1:635e76c52151 70 IpDestination=1;
seppeduwe 1:635e76c52151 71 sprintf(destIp,"192.168.0.1%02i",IpDestination);
seppeduwe 4:466d859bfb13 72 display.setText("IP:192.168.0.1%02i",IpDestination);
seppeduwe 1:635e76c52151 73 BoolIpDestination=0;
seppeduwe 1:635e76c52151 74 wait(0.5);
seppeduwe 1:635e76c52151 75 }
seppeduwe 1:635e76c52151 76 if(Send) {
seppeduwe 3:344115c04cd0 77 dataFrame.setIdDestinationMbed(IpDestination);
seppeduwe 3:344115c04cd0 78 dataFrame.setTemperature(temp.getTemperature());
seppeduwe 3:344115c04cd0 79 dataFrame.setPWMDutycycle(potentiometer.getPotentiometer());
seppeduwe 4:466d859bfb13 80 tune.play(1);
seppeduwe 4:466d859bfb13 81 dataFrame.setTune(2);
seppeduwe 3:344115c04cd0 82 dataFrame.AddID(7);
seppeduwe 1:635e76c52151 83 //char testIDs[]= {0x08,0x09,0x0A};
seppeduwe 3:344115c04cd0 84 //dataFrame->setLengthIDs(3);
seppeduwe 3:344115c04cd0 85 //dataFrame->setIDs(testIDs);
seppeduwe 3:344115c04cd0 86 dataFrame.Encode(buf);
seppeduwe 0:ae3af7d18c4a 87
seppeduwe 1:635e76c52151 88 server.connect(destIp);
seppeduwe 0:ae3af7d18c4a 89 server.send(buf);
seppeduwe 1:635e76c52151 90 Send=0;
seppeduwe 1:635e76c52151 91 wait(0.5);
seppeduwe 0:ae3af7d18c4a 92 }
seppeduwe 0:ae3af7d18c4a 93 }
seppeduwe 2:1243006bb879 94 }