Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: xtoff2 RF24Network mbed
Fork of xtoff3 by
Revision 12:a3dd2ebf8f93, committed 2018-03-12
- Comitter:
- pietor
- Date:
- Mon Mar 12 10:56:50 2018 +0000
- Parent:
- 11:77018fac195e
- Child:
- 13:f54dfb74247e
- Commit message:
- test 12/03;
Changed in this revision
| Ontvanger.h | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/Ontvanger.h Fri Mar 09 12:22:27 2018 +0000
+++ b/Ontvanger.h Mon Mar 12 10:56:50 2018 +0000
@@ -30,7 +30,7 @@
enum State2 {init_state,
send_state,
- receive_state
+ receive_state,
};
enum State {State_init,
@@ -38,7 +38,8 @@
State_position,
State_read,
State_send,
- State_receive
+ State_receive,
+ State_calibrate
};
struct state_Packet {
--- 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);
}
