Projectlab Elektronica-ICT KULeuven
Dependencies: EthernetInterface TMP102 TextLCD mbed-rtos mbed
Diff: main.cpp
- Revision:
- 3:344115c04cd0
- Parent:
- 2:1243006bb879
- Child:
- 4:466d859bfb13
--- a/main.cpp Sun Mar 16 16:52:27 2014 +0000 +++ b/main.cpp Sun Mar 16 18:56:08 2014 +0000 @@ -30,7 +30,7 @@ buttonDestinationIpUp.rise(&DestinationIpUp); // attach the address of the flip function to the rising edge char buf[256]; - Frame testFrame; + Frame dataFrame; Server server("192.168.0.107"); server.printStatus(); Display display; @@ -41,22 +41,23 @@ while(1) { if(server.read(buf)) { - if(!testFrame.Decode(buf)) + if(!dataFrame.Decode(buf)) printf("Frame CRC Error \n\r"); - if(testFrame.getIdDestinationMbed()==7) { + if(dataFrame.getIdDestinationMbed()==7) { printf("Voor mij\n\r"); - PWMout=potentiometer.getPotentiometer()/100; - tune.play(testFrame.getTune()); - //display.setText("Temp: %d",(0.026862*(testFrame.getTemperature()-25))); - display.setText("Temp: %d",testFrame.getTemperature()); - testFrame.setIdDestinationMbed(IpDestination); - testFrame.setTemperature(temp.getTemperature()); - testFrame.setPWMDutycycle(potentiometer.getPotentiometer()); - testFrame.setTune(testFrame.getTune()+1); - testFrame.AddID(7); - testFrame.Encode(buf); + PWMout=potentiometer.getPotentiometer(); + PWMout.period(0.010);// set PWM period to 10 ms + tune.play(dataFrame.getTune()); + display.setText("Temp: %d °C",dataFrame.getTemperature()); + //display.setText("Temp: %d",dataFrame.getTemperature()); + dataFrame.setIdDestinationMbed(IpDestination); + dataFrame.setTemperature(temp.getTemperature()); + dataFrame.setPWMDutycycle(potentiometer.getPotentiometer()); + dataFrame.setTune(dataFrame.getTune()+1); + dataFrame.AddID(7); + dataFrame.Encode(buf); } - if(!testFrame.CheckMyID(7)) { + if(!dataFrame.CheckMyID(7)) { server.connect(destIp); server.send(buf); } @@ -67,20 +68,20 @@ else IpDestination=1; sprintf(destIp,"192.168.0.1%02i",IpDestination); - display.setText("192.168.0.1%02i",IpDestination); + display.setText("IP: 192.168.0.1%02i",IpDestination); BoolIpDestination=0; wait(0.5); } if(Send) { - testFrame.setIdDestinationMbed(IpDestination); - testFrame.setTemperature(temp.getTemperature()); - testFrame.setPWMDutycycle(potentiometer.getPotentiometer()); - testFrame.setTune(1); - testFrame.AddID(7); + dataFrame.setIdDestinationMbed(IpDestination); + dataFrame.setTemperature(temp.getTemperature()); + dataFrame.setPWMDutycycle(potentiometer.getPotentiometer()); + dataFrame.setTune(1); + dataFrame.AddID(7); //char testIDs[]= {0x08,0x09,0x0A}; - //testFrame->setLengthIDs(3); - //testFrame->setIDs(testIDs); - testFrame.Encode(buf); + //dataFrame->setLengthIDs(3); + //dataFrame->setIDs(testIDs); + dataFrame.Encode(buf); server.connect(destIp); server.send(buf);