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: main.cpp
- Revision:
- 1:41844163cb7f
- Parent:
- 0:755a36a9fc5c
diff -r 755a36a9fc5c -r 41844163cb7f main.cpp
--- a/main.cpp Sat Mar 23 22:47:55 2019 +0000
+++ b/main.cpp Tue Mar 26 17:45:39 2019 +0000
@@ -1,25 +1,32 @@
#include "mbed.h"
-
-Serial pc(USBTX, USBRX,9600);
-Serial blue(PTC15, PTC14, 115200); //tx, rx
-Serial other(PTC17, PTC16, 115200);
+//tx, rx, baud rate
+Serial pc(USBTX, USBRX,9600);
+Serial blue(PTC15, PTC14, 115200); // for comm with bluetooth hc06
+Serial other(PTC17, PTC16, 115200);// for comm with S32K
Ticker locker;
-char prev = 'z';
+char prev = 'z'; //init states for use to determine if car needs to be locked
char current = 'y';
bool nflag = true;
+// A callback function used to determine if car needs to be locked
+// it is called
void lockCar()
{
pc.printf("ticker\r\n\r");
char send[] = "bj";
+
+ //checks to see if not already locked
if(nflag)
{
+ //if no new key is pressed lock car
if(prev == current)
{
+ //stops motor.
for(int i = 1; i< 50; i++){other.putc(send[1]);}
wait(5);
+ //locks car
for(int i = 1; i< 50; i++){other.putc(send[0]);}
prev = 'z';
nflag = false;
@@ -33,25 +40,34 @@
int main()
{
- int i = 0;
+ int i = 0;//init variables
int j = 0;
char hold[100] ="String";
- locker.attach(&lockCar, 15.0);
+ //attaches the callback function to a timer
+ locker.attach(&lockCar, 20.0);
pc.printf(hold);
+ //controlling loop
while (true)
{
+ //read from bluetooth if something is avalible
while(blue.readable())
{
+ //puts characters from bluetooth in buffer
hold[j++] = blue.getc();
i = 10;
nflag = true;
}
+ //if buffer has elements
while(i)
{
+ //put null at end of string
hold[j] = '\0';
+ //send element to S32K
other.putc(hold[0]);
+ //update flag for locking system
current = hold[0];
+ //display info to tera term
pc.printf("%d:", i);
pc.printf(hold);
pc.putc('\n');