Projectlab Elektronica-ICT KULeuven

Dependencies:   EthernetInterface TMP102 TextLCD mbed-rtos mbed

werking.pdf

Committer:
seppeduwe
Date:
Sun Mar 16 18:56:08 2014 +0000
Revision:
3:344115c04cd0
Parent:
2:1243006bb879
Child:
4:466d859bfb13
Range Temp en PWM

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 3:344115c04cd0 46 if(dataFrame.getIdDestinationMbed()==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 3:344115c04cd0 51 display.setText("Temp: %d °C",dataFrame.getTemperature());
seppeduwe 3:344115c04cd0 52 //display.setText("Temp: %d",dataFrame.getTemperature());
seppeduwe 3:344115c04cd0 53 dataFrame.setIdDestinationMbed(IpDestination);
seppeduwe 3:344115c04cd0 54 dataFrame.setTemperature(temp.getTemperature());
seppeduwe 3:344115c04cd0 55 dataFrame.setPWMDutycycle(potentiometer.getPotentiometer());
seppeduwe 3:344115c04cd0 56 dataFrame.setTune(dataFrame.getTune()+1);
seppeduwe 3:344115c04cd0 57 dataFrame.AddID(7);
seppeduwe 3:344115c04cd0 58 dataFrame.Encode(buf);
seppeduwe 1:635e76c52151 59 }
seppeduwe 3:344115c04cd0 60 if(!dataFrame.CheckMyID(7)) {
seppeduwe 1:635e76c52151 61 server.connect(destIp);
seppeduwe 1:635e76c52151 62 server.send(buf);
seppeduwe 1:635e76c52151 63 }
seppeduwe 0:ae3af7d18c4a 64 }
seppeduwe 1:635e76c52151 65 if(BoolIpDestination) {
seppeduwe 1:635e76c52151 66 if(IpDestination!=15)
seppeduwe 1:635e76c52151 67 IpDestination++;
seppeduwe 1:635e76c52151 68 else
seppeduwe 1:635e76c52151 69 IpDestination=1;
seppeduwe 1:635e76c52151 70 sprintf(destIp,"192.168.0.1%02i",IpDestination);
seppeduwe 3:344115c04cd0 71 display.setText("IP: 192.168.0.1%02i",IpDestination);
seppeduwe 1:635e76c52151 72 BoolIpDestination=0;
seppeduwe 1:635e76c52151 73 wait(0.5);
seppeduwe 1:635e76c52151 74 }
seppeduwe 1:635e76c52151 75 if(Send) {
seppeduwe 3:344115c04cd0 76 dataFrame.setIdDestinationMbed(IpDestination);
seppeduwe 3:344115c04cd0 77 dataFrame.setTemperature(temp.getTemperature());
seppeduwe 3:344115c04cd0 78 dataFrame.setPWMDutycycle(potentiometer.getPotentiometer());
seppeduwe 3:344115c04cd0 79 dataFrame.setTune(1);
seppeduwe 3:344115c04cd0 80 dataFrame.AddID(7);
seppeduwe 1:635e76c52151 81 //char testIDs[]= {0x08,0x09,0x0A};
seppeduwe 3:344115c04cd0 82 //dataFrame->setLengthIDs(3);
seppeduwe 3:344115c04cd0 83 //dataFrame->setIDs(testIDs);
seppeduwe 3:344115c04cd0 84 dataFrame.Encode(buf);
seppeduwe 0:ae3af7d18c4a 85
seppeduwe 1:635e76c52151 86 server.connect(destIp);
seppeduwe 0:ae3af7d18c4a 87 server.send(buf);
seppeduwe 1:635e76c52151 88 Send=0;
seppeduwe 1:635e76c52151 89 wait(0.5);
seppeduwe 0:ae3af7d18c4a 90 }
seppeduwe 0:ae3af7d18c4a 91 }
seppeduwe 2:1243006bb879 92 }