Code to run tests on the Ethernet library
Dependencies: EthernetInterface mbed-rtos mbed
main.cpp@3:021bdd25958a, 2013-10-28 (annotated)
- Committer:
- lawless
- Date:
- Mon Oct 28 23:05:43 2013 +0000
- Revision:
- 3:021bdd25958a
- Parent:
- 2:483bc2e71bfe
It worked! yay
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lawless | 0:3f5638515f99 | 1 | #include "mbed.h" |
lawless | 0:3f5638515f99 | 2 | #include "EthernetInterface.h" |
lawless | 1:effed2d57b6c | 3 | |
lawless | 3:021bdd25958a | 4 | |
lawless | 3:021bdd25958a | 5 | PwmOut pump_tick(LED1); |
lawless | 3:021bdd25958a | 6 | DigitalOut tick(LED2); |
lawless | 1:effed2d57b6c | 7 | Ticker pkt; |
lawless | 1:effed2d57b6c | 8 | InterruptIn *flow; |
lawless | 2:483bc2e71bfe | 9 | PwmOut *pump; |
lawless | 1:effed2d57b6c | 10 | |
lawless | 1:effed2d57b6c | 11 | unsigned int flowcount = 0; |
lawless | 3:021bdd25958a | 12 | unsigned int lastflow; |
lawless | 3:021bdd25958a | 13 | |
lawless | 1:effed2d57b6c | 14 | float pi = 3.1415926535897932384626433832795; |
lawless | 1:effed2d57b6c | 15 | |
lawless | 1:effed2d57b6c | 16 | void flowtick() { |
lawless | 3:021bdd25958a | 17 | tick.write(1); |
lawless | 1:effed2d57b6c | 18 | flowcount++; |
lawless | 3:021bdd25958a | 19 | tick.write(0); |
lawless | 1:effed2d57b6c | 20 | } |
lawless | 1:effed2d57b6c | 21 | |
lawless | 3:021bdd25958a | 22 | int main() { |
lawless | 3:021bdd25958a | 23 | |
lawless | 3:021bdd25958a | 24 | EthernetInterface eth; |
lawless | 2:483bc2e71bfe | 25 | UDPSocket sock; |
lawless | 3:021bdd25958a | 26 | Endpoint seven; |
lawless | 3:021bdd25958a | 27 | eth.init("192.168.9.8", "255.255.255.0", "192.168.9.1"); |
lawless | 3:021bdd25958a | 28 | eth.connect(); |
lawless | 2:483bc2e71bfe | 29 | sock.init(); |
lawless | 1:effed2d57b6c | 30 | seven.set_address("192.168.9.7", 37); |
lawless | 1:effed2d57b6c | 31 | char out_buffer[8]; // Does not matter |
lawless | 3:021bdd25958a | 32 | |
lawless | 1:effed2d57b6c | 33 | flow = new InterruptIn(p5); |
lawless | 3:021bdd25958a | 34 | flow->mode(PullUp); |
lawless | 2:483bc2e71bfe | 35 | pump = new PwmOut(p21); |
lawless | 0:3f5638515f99 | 36 | |
lawless | 2:483bc2e71bfe | 37 | pump->period(1.0); |
lawless | 3:021bdd25958a | 38 | pump_tick.period(1.0); |
lawless | 3:021bdd25958a | 39 | |
lawless | 3:021bdd25958a | 40 | lastflow = flowcount; |
lawless | 0:3f5638515f99 | 41 | |
lawless | 1:effed2d57b6c | 42 | flow->rise(&flowtick); |
lawless | 0:3f5638515f99 | 43 | |
lawless | 1:effed2d57b6c | 44 | float t = 0.0; |
lawless | 1:effed2d57b6c | 45 | while(1) { |
lawless | 1:effed2d57b6c | 46 | if(t < pi) { |
lawless | 1:effed2d57b6c | 47 | t += 0.01; |
lawless | 2:483bc2e71bfe | 48 | pump->write(1 - cos(t)); |
lawless | 3:021bdd25958a | 49 | pump_tick.write(1 - cos(t)); |
lawless | 1:effed2d57b6c | 50 | } |
lawless | 1:effed2d57b6c | 51 | |
lawless | 1:effed2d57b6c | 52 | wait(0.1); |
lawless | 3:021bdd25958a | 53 | if(flowcount > lastflow) { |
lawless | 3:021bdd25958a | 54 | sprintf(out_buffer, "%07d", flowcount); |
lawless | 3:021bdd25958a | 55 | sock.sendTo(seven, out_buffer, sizeof(out_buffer)); |
lawless | 3:021bdd25958a | 56 | lastflow = flowcount; |
lawless | 3:021bdd25958a | 57 | } |
lawless | 0:3f5638515f99 | 58 | } |
lawless | 3:021bdd25958a | 59 | sock.close(); |
lawless | 3:021bdd25958a | 60 | eth.disconnect(); |
lawless | 0:3f5638515f99 | 61 | } |