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: XBeeLib mbed-rtos mbed
Fork of Capteurs-Beginner by
Revision 7:e11d6545731a, committed 2016-04-06
- Comitter:
- vinbel93
- Date:
- Wed Apr 06 20:16:07 2016 +0000
- Parent:
- 6:19b89212e67f
- Child:
- 8:096edc8e8679
- Commit message:
- gp2d12
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Apr 04 18:55:08 2016 +0000
+++ b/main.cpp Wed Apr 06 20:16:07 2016 +0000
@@ -8,9 +8,10 @@
XBeeZB* xbee;
-DigitalIn capteur_1(p15);
-DigitalIn capteur_2(p16);
-DigitalIn capteur_3(p17);
+AnalogIn GP2D12(p15);
+DigitalIn capteur_1(p16);
+DigitalIn capteur_2(p17);
+DigitalIn capteur_3(p18);
DigitalIn capteur_4(p19);
DigitalIn capteur_5(p20);
DigitalIn capteur_6(p21);
@@ -23,6 +24,8 @@
bool capt_4;
bool capt_5;
bool capt_6;
+
+uint16_t GP2D12_value;
/* lecture des capteurs à partir des broches du mbed : p15, p16, p17, 19, 20 21*/
@@ -36,21 +39,28 @@
capt_5=capteur_5.read();
capt_6=capteur_6.read();
+ GP2D12_value = GP2D12.read_u16();
+
+
capt_lock.unlock();
}
void send_data_to_coordinator(const uint8_t* data)
{
- const TxStatus txStatus = xbee->send_data_to_coordinator(data, 1);
+ const TxStatus txStatus = xbee->send_data_to_coordinator(data, 2);
}
void envoi_donnees (void const *args) {
capt_lock.lock();
- uint8_t data = (capt_1 << 7) | (capt_2 << 6) | (capt_3 << 5) | (capt_4 << 4) | (capt_5 << 3) | (capt_6 << 2);
- pc.printf("%02x ", data);
+ uint8_t data[3];
+ data[0] = (capt_1 << 7) | (capt_2 << 6) | (capt_3 << 5) | (capt_4 << 4) | (capt_5 << 3) | (capt_6 << 2);
+ data[1] = (GP2D12_value & 0xFF00) >> 8;
+
+ pc.printf("%x \n\r", GP2D12_value);
+ pc.printf("%02x %02x %02x\n\r", data[0], data[1], data[2]);
capt_lock.unlock();
- send_data_to_coordinator(&data);
+ send_data_to_coordinator(data);
}
int main (void) {
@@ -59,8 +69,8 @@
RtosTimer readTimer(lecture_capteurs, osTimerPeriodic);
RtosTimer sendTimer(envoi_donnees, osTimerPeriodic);
- readTimer.start(500);
- sendTimer.start(500);
+ readTimer.start(50);
+ sendTimer.start(50);
wait(osWaitForever);
}
\ No newline at end of file
