![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
dd
Dependencies: xtoff2 RF24Network mbed
Fork of xtoff3 by
main.cpp
- Committer:
- pietor
- Date:
- 2018-03-09
- Revision:
- 11:77018fac195e
- Parent:
- 10:0a4c465f7838
- Child:
- 12:a3dd2ebf8f93
File content as of revision 11:77018fac195e:
/** Main.cpp Purpose: main class @author Pieter Berteloot RF24 PINOUT: ---- ----- |GND | VCC | |---- | |CE CSN | |SCK MOSI| |MISO IRQ | ---- ----- ---- ----- |GND | Vout| |---- | |p9 p8 | |p7 p5 | |p6 NC | ---- ----- */ //uncommend #define PRINT_ENABLE to see informational prints //#define PRINT_ENABLE #include "mbed.h" #include "Ontvanger.h" Serial pc(USBTX, USBRX); Ontvanger receive; Timer t; DigitalOut myled1(LED1); DigitalOut myled2(LED2); DigitalOut myled3(LED3); DigitalOut myled4(LED4); State2 current_state = init_state; void acitvateLed() { t.reset(); } void setCurrentState( State2 setState ) { current_state = setState; } State2 getCurrentState() { return current_state; } int main() { 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: pc.baud(9600); t.start(); state_Packet packet; payload_t payload; setCurrentState(receive_state); break; case send_state: IF_PRINT_ENABLE(pc.printf("Send State\n\r");); packet.setState = State_position; bool ok = receive.write(packet); if (ok) IF_PRINT_ENABLE(pc.printf("ok.\n\r");); else IF_PRINT_ENABLE(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("%f\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; } } }