Projectlab Elektronica-ICT KULeuven
Dependencies: EthernetInterface TMP102 TextLCD mbed-rtos mbed
main.cpp
- Committer:
- seppeduwe
- Date:
- 2014-03-16
- Revision:
- 1:635e76c52151
- Parent:
- 0:ae3af7d18c4a
- Child:
- 2:1243006bb879
File content as of revision 1:635e76c52151:
#include "mbed.h" #include "Server.h" #include "Frame.h" #include "Tune.h" #include "Display.h" #include "Temperature.h" #include "Potentiometer.h" InterruptIn buttonSend(p8); bool Send; void SendISR() { Send=1; } InterruptIn buttonDestinationIpUp(p7); int IpDestination=10; bool BoolIpDestination; char destIp[14]; void DestinationIpUp() { BoolIpDestination=1; } //PWM-signaal gegenereerd op basis van de potentiometerwaarde PwmOut PWMout(p22); int main() { buttonSend.rise(&SendISR); // attach the address of the flip function to the rising edge buttonDestinationIpUp.rise(&DestinationIpUp); // attach the address of the flip function to the rising edge char buf[256]; Frame* testFrame = new Frame(); Server server("192.168.0.107"); server.printStatus(); Display* display=new Display(); display->setText("Seppe's MBED"); Tune* tune = new Tune(); Temperature temp; Potentiometer* potentiometer = new Potentiometer(); while(1) { if(server.read(buf)) { if(!testFrame->Decode(buf)) printf("Frame CRC Error \n\r"); if(testFrame->getIdDestinationMbed()==7) { printf("Voor mij\n\r"); PWMout=potentiometer->getPotentiometer()/100; tune->play(testFrame->getTune()); 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); } if(!testFrame->CheckMyID(7)) { server.connect(destIp); server.send(buf); } } if(BoolIpDestination) { if(IpDestination!=15) IpDestination++; else IpDestination=1; sprintf(destIp,"192.168.0.1%02i",IpDestination); display->setText("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); //char testIDs[]= {0x08,0x09,0x0A}; //testFrame->setLengthIDs(3); //testFrame->setIDs(testIDs); testFrame->Encode(buf); server.connect(destIp); server.send(buf); Send=0; wait(0.5); } } }