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.
Diff: communication.cpp
- Revision:
- 13:e3089b058fab
- Parent:
- 12:1c7b59097090
--- a/communication.cpp Mon Dec 19 17:47:06 2016 +0000
+++ b/communication.cpp Mon Dec 19 18:54:01 2016 +0000
@@ -2,7 +2,15 @@
#include "mbed.h"
//DigitalOut cervena(LED1);
//DigitalOut zelena(LED2);
-
+#include "MMA8451Q.h"
+#define MMA8451_I2C_ADDRESS (0x1d<<1)
+#define ON 0
+#define OFF !ON
+//Setup the interrupts for the MMA8451Q
+InterruptIn accInt1(PTA14);
+InterruptIn accInt2(PTA15);//not used in this prog but this is the other int from the accelorometer
+uint8_t togstat=0;//Led status
+DigitalOut bled(LED_BLUE);
communication::communication(Serial *_pc):zelena(LED2),cervena(LED1)
{
pc=_pc;
@@ -17,10 +25,34 @@
mapPoschodie.insert(pair<string, bool>("p3",false));
mapPoschodie.insert(pair<string, bool>("p4",false));
mapPoschodie.insert(pair<string, bool>("p0",false));
+ sendDataOk=false;
poschodie=4;
watchDog[0]=0x01;
sendPacket(0xa0,0xfe,0x0, watchDog,1);
- watchDog[1]=0x02;
+ watchDog[0]=0x02;
+ MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);
+ acc.setDoubleTap();
+ accInt1.rise(this,&communication::tapTrue);
+}
+void communication::tapTrue(void)
+{
+ if(togstat == 0) {
+ breakEm[0]=0x01;
+ sendPacket(0xa0,0xf,0x00,breakEm,1);
+ togstat = 1;
+ bled=ON;
+ } else if(togstat==1) {
+ breakEm[0]=0x00;
+ /*deaktivacia brzdy*/
+ sendPacket(0xa0,0xf,0x00,breakEm,1);
+ togstat = 2;
+ bled=OFF;
+ } else {
+ togstat=0;
+ watchDog[0]=0x01;
+ sendPacket(0xa0,0xfe,0x00,watchDog,1);
+ bled=ON;
+ }
}
unsigned char communication::crcArray[]= {