![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
dd
Dependencies: xtoff2 RF24Network mbed
Fork of xtoff3 by
main.cpp@15:f8aad6d1db68, 2018-07-13 (annotated)
- Committer:
- gimohd
- Date:
- Fri Jul 13 06:28:33 2018 +0000
- Revision:
- 15:f8aad6d1db68
- Parent:
- 14:3e69c8a9c730
- Child:
- 16:691649d8a3da
dd
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pietor | 4:7ebc3b421306 | 1 | /** |
pietor | 4:7ebc3b421306 | 2 | Main.cpp |
pietor | 4:7ebc3b421306 | 3 | Purpose: main class |
pietor | 4:7ebc3b421306 | 4 | |
pietor | 4:7ebc3b421306 | 5 | @author Pieter Berteloot |
pietor | 12:a3dd2ebf8f93 | 6 | |
pietor | 11:77018fac195e | 7 | RF24 PINOUT: |
pietor | 11:77018fac195e | 8 | ---- ----- |
pietor | 12:a3dd2ebf8f93 | 9 | |GND | VCC | |
pietor | 11:77018fac195e | 10 | |---- | |
pietor | 11:77018fac195e | 11 | |CE CSN | |
pietor | 11:77018fac195e | 12 | |SCK MOSI| |
pietor | 11:77018fac195e | 13 | |MISO IRQ | |
pietor | 11:77018fac195e | 14 | ---- ----- |
pietor | 12:a3dd2ebf8f93 | 15 | |
pietor | 11:77018fac195e | 16 | ---- ----- |
pietor | 12:a3dd2ebf8f93 | 17 | |GND | Vout| |
pietor | 11:77018fac195e | 18 | |---- | |
pietor | 11:77018fac195e | 19 | |p9 p8 | |
pietor | 11:77018fac195e | 20 | |p7 p5 | |
pietor | 11:77018fac195e | 21 | |p6 NC | |
pietor | 12:a3dd2ebf8f93 | 22 | ---- ----- |
pietor | 4:7ebc3b421306 | 23 | */ |
pietor | 11:77018fac195e | 24 | //uncommend #define PRINT_ENABLE to see informational prints |
pietor | 14:3e69c8a9c730 | 25 | #define PRINT_ENABLE |
pietor | 11:77018fac195e | 26 | |
akashvibhute | 0:3982c0e9eda1 | 27 | #include "mbed.h" |
gimohd | 15:f8aad6d1db68 | 28 | //#include "rtos.h" |
pietor | 4:7ebc3b421306 | 29 | #include "Ontvanger.h" |
pietor | 4:7ebc3b421306 | 30 | |
akashvibhute | 0:3982c0e9eda1 | 31 | Serial pc(USBTX, USBRX); |
gimohd | 15:f8aad6d1db68 | 32 | Ontvanger receiver; |
pietor | 6:6a82110ff393 | 33 | Timer t; |
pietor | 6:6a82110ff393 | 34 | |
pietor | 9:e14f65b8ffc2 | 35 | DigitalOut myled1(LED1); |
pietor | 9:e14f65b8ffc2 | 36 | DigitalOut myled2(LED2); |
pietor | 9:e14f65b8ffc2 | 37 | DigitalOut myled3(LED3); |
pietor | 9:e14f65b8ffc2 | 38 | DigitalOut myled4(LED4); |
pietor | 7:8515f205483b | 39 | |
pietor | 7:8515f205483b | 40 | State2 current_state = init_state; |
pietor | 7:8515f205483b | 41 | |
gimohd | 15:f8aad6d1db68 | 42 | |
gimohd | 15:f8aad6d1db68 | 43 | //Thread thread; |
gimohd | 15:f8aad6d1db68 | 44 | //Mutex stdio_mutex; |
gimohd | 15:f8aad6d1db68 | 45 | //Mutex nrf_mutex; |
gimohd | 15:f8aad6d1db68 | 46 | |
gimohd | 15:f8aad6d1db68 | 47 | void receive() |
pietor | 6:6a82110ff393 | 48 | { |
gimohd | 15:f8aad6d1db68 | 49 | while (true) { |
gimohd | 15:f8aad6d1db68 | 50 | pc.printf("");//print niet weg doen, één of andere reden werkt het niet zonder |
gimohd | 15:f8aad6d1db68 | 51 | receiver.update(); |
gimohd | 15:f8aad6d1db68 | 52 | if (receiver.available()) { |
gimohd | 15:f8aad6d1db68 | 53 | payload_t payload; |
gimohd | 15:f8aad6d1db68 | 54 | payload = receiver.read(); |
gimohd | 15:f8aad6d1db68 | 55 | if(!payload.messageAvailable) { |
gimohd | 15:f8aad6d1db68 | 56 | pc.printf("%f\r\n", payload.gram); |
gimohd | 15:f8aad6d1db68 | 57 | } |
gimohd | 15:f8aad6d1db68 | 58 | } |
gimohd | 15:f8aad6d1db68 | 59 | } |
pietor | 6:6a82110ff393 | 60 | } |
pietor | 6:6a82110ff393 | 61 | |
gimohd | 15:f8aad6d1db68 | 62 | void send() |
pietor | 7:8515f205483b | 63 | { |
gimohd | 15:f8aad6d1db68 | 64 | //bool ok = receive.write(packet); |
gimohd | 15:f8aad6d1db68 | 65 | bool ok = true; |
gimohd | 15:f8aad6d1db68 | 66 | if (ok) |
gimohd | 15:f8aad6d1db68 | 67 | pc.printf("Vok.\n\r"); |
gimohd | 15:f8aad6d1db68 | 68 | else |
gimohd | 15:f8aad6d1db68 | 69 | pc.printf("Vfailed.\n\r"); |
pietor | 7:8515f205483b | 70 | } |
pietor | 7:8515f205483b | 71 | |
pietor | 7:8515f205483b | 72 | |
gimohd | 15:f8aad6d1db68 | 73 | /** |
gimohd | 15:f8aad6d1db68 | 74 | char c = 'a'; |
gimohd | 15:f8aad6d1db68 | 75 | void led2_thread() |
pietor | 7:8515f205483b | 76 | { |
gimohd | 15:f8aad6d1db68 | 77 | while (true) { |
gimohd | 15:f8aad6d1db68 | 78 | stdio_mutex.lock(); |
gimohd | 15:f8aad6d1db68 | 79 | //c = pc.getc(); |
gimohd | 15:f8aad6d1db68 | 80 | pc.printf("Character %c\r\n", c); |
gimohd | 15:f8aad6d1db68 | 81 | stdio_mutex.unlock(); |
gimohd | 15:f8aad6d1db68 | 82 | } |
gimohd | 15:f8aad6d1db68 | 83 | }**/ |
pietor | 7:8515f205483b | 84 | |
akashvibhute | 2:608cf8c5c55e | 85 | int main() |
akashvibhute | 0:3982c0e9eda1 | 86 | { |
gimohd | 15:f8aad6d1db68 | 87 | float massa = 69; |
gimohd | 15:f8aad6d1db68 | 88 | //thread.start(receive); |
gimohd | 15:f8aad6d1db68 | 89 | while (true) { |
gimohd | 15:f8aad6d1db68 | 90 | pc.printf(""); |
gimohd | 15:f8aad6d1db68 | 91 | wait_ms(100); |
gimohd | 15:f8aad6d1db68 | 92 | receiver.update(); |
gimohd | 15:f8aad6d1db68 | 93 | payload_t payload; |
gimohd | 15:f8aad6d1db68 | 94 | massa++; |
gimohd | 15:f8aad6d1db68 | 95 | payload.gram = massa; |
gimohd | 15:f8aad6d1db68 | 96 | bool ok = receiver.write(payload); |
gimohd | 15:f8aad6d1db68 | 97 | if (ok) |
gimohd | 15:f8aad6d1db68 | 98 | pc.printf("ok.\r\n"); |
gimohd | 15:f8aad6d1db68 | 99 | else |
gimohd | 15:f8aad6d1db68 | 100 | pc.printf("failed.\r\n"); |
akashvibhute | 0:3982c0e9eda1 | 101 | } |
gimohd | 15:f8aad6d1db68 | 102 | } |