in d mix
Dependencies: xtoff2 RF24Network mbed
Fork of RF24Network_Receive by
Diff: main.cpp
- Revision:
- 12:a3dd2ebf8f93
- Parent:
- 11:77018fac195e
- Child:
- 13:f54dfb74247e
--- a/main.cpp Fri Mar 09 12:22:27 2018 +0000 +++ b/main.cpp Mon Mar 12 10:56:50 2018 +0000 @@ -3,26 +3,26 @@ Purpose: main class @author Pieter Berteloot - + RF24 PINOUT: ---- ----- - |GND | VCC | + |GND | VCC | |---- | |CE CSN | |SCK MOSI| |MISO IRQ | ---- ----- - + ---- ----- - |GND | Vout| + |GND | Vout| |---- | |p9 p8 | |p7 p5 | |p6 NC | - ---- ----- + ---- ----- */ //uncommend #define PRINT_ENABLE to see informational prints -//#define PRINT_ENABLE +#define PRINT_ENABLE #include "mbed.h" #include "Ontvanger.h" @@ -36,6 +36,8 @@ DigitalOut myled3(LED3); DigitalOut myled4(LED4); +char c; + State2 current_state = init_state; void acitvateLed() @@ -56,14 +58,15 @@ int main() { - IF_PRINT_ENABLE( pc.printf("\r\nOntvanger: \r\n"); - pc.printf("testing Radio... %d\r\n", receive.isValid()); - ); - + IF_PRINT_ENABLE( pc.printf("\r\nOntvanger: \r\n"); + pc.printf("testing Radio... %d\r\n", receive.isValid()); + ); + while(1) { receive.update(); switch (current_state) { case init_state: + IF_PRINT_ENABLE(pc.printf("Init State\n\r");); pc.baud(9600); t.start(); state_Packet packet; @@ -73,7 +76,13 @@ case send_state: IF_PRINT_ENABLE(pc.printf("Send State\n\r");); - packet.setState = State_position; + if(c == 's') { + IF_PRINT_ENABLE(pc.printf("Send state: Tare\n\r");); + packet.setState = State_tare; + } else if (c == 'c') { + IF_PRINT_ENABLE(pc.printf("Send state: Calibrate\n\r");); + packet.setState = State_calibrate; + } bool ok = receive.write(packet); if (ok) IF_PRINT_ENABLE(pc.printf("ok.\n\r");); @@ -84,25 +93,24 @@ break; case receive_state: - pc.printf("");//print niet weg doen, één of andere reden werkt het dan wel + pc.printf("");//print niet weg doen, één of andere reden werkt het niet zonder if (receive.available()) { payload_t payload; payload = receive.read(); pc.printf("%f\r\n", payload.milligram); if (payload.reedsensor) { - acitvateLed(); + acitvateLed(); } } - if (t.read() <= 1){ + if (t.read() <= 1) { myled1 = myled2 = myled3 = myled4 = 1; - } - else + } else myled1 = myled2 = myled3 = myled4 = 0; if(pc.readable()) { - char c = pc.getc(); - if(c == 's') + c = pc.getc(); + if(c == 's' or c == 'c') setCurrentState(send_state); wait(0.5); }