![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
in d mix
Dependencies: xtoff2 RF24Network mbed
Fork of RF24Network_Receive by
Diff: main.cpp
- Revision:
- 7:8515f205483b
- Parent:
- 6:6a82110ff393
- Child:
- 8:c43411433ce1
diff -r 6a82110ff393 -r 8515f205483b main.cpp --- a/main.cpp Mon Feb 19 14:44:11 2018 +0000 +++ b/main.cpp Wed Feb 21 12:05:17 2018 +0000 @@ -18,28 +18,79 @@ Timer t; +enum State2 {init_state, + send_state, + receive_state + }; + +State2 current_state = init_state; + void acitvateLed() { t.reset(); } +void setCurrentState( State2 setState ) +{ + current_state = setState; +} + + +State2 getCurrentState() +{ + return current_state; +} + int main() { - pc.baud(9600); - pc.printf("Ontvangger: \r\n"); - t.start(); while(1) { receive.update(); - while (receive.available()) { - payload_t payload; - payload = receive.read(); - pc.printf("%d\r\n",payload.milligram); - if (payload.reedsensor) - acitvateLed(); + switch (current_state) { + case init_state: + pc.baud(9600); + pc.printf("Ontvangger: \r\n"); + t.start(); + state_Packet packet; + payload_t payload; + setCurrentState(receive_state); + break; + + case send_state: + packet.setState = State_position; + bool ok = receive.write(packet); + if (ok) + pc.printf("ok.\n\r"); + else + pc.printf("failed.\n\r"); + wait(0.1); + setCurrentState(receive_state); + break; + + case receive_state: + pc.printf("");//print niet weg doen, één of andere reden werkt het dan wel + + if (receive.available()) { + payload_t payload; + payload = receive.read(); + pc.printf("massa = %d\r\n",payload.milligram); + if (payload.reedsensor) { + acitvateLed(); + } + } + + if (t.read() <= 1) + myled1 = myled2 = myled3 = myled4 = 1; + else + myled1 = myled2 = myled3 = myled4 = 0; + + if(pc.readable()) { + char c = pc.getc(); + if(c == 's') + setCurrentState(send_state); + wait(0.5); + } + break; + } - if (t.read() <= 1) - myled1 = myled2 = myled3 = myled4 = 1; - else - myled1 = myled2 = myled3 = myled4 = 0; } } \ No newline at end of file