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: MMA8451Q mbed tsi_sensor
Fork of UTCSBootcamp by
KnockAPI.cpp
00001 #include "KnockAPI.h" 00002 #include "Includes/KnockBaseAPI.h" 00003 00004 #define MMA8451_I2C_ADDRESS (0x1d<<1) 00005 00006 Timer timer; 00007 00008 void print(const char* msg, ...){ 00009 char buffer[256]; 00010 va_list args; 00011 va_start (args, msg); 00012 vsprintf (buffer,msg, args); 00013 va_end (args); 00014 port.printf(buffer); 00015 } 00016 00017 /************************************************ 00018 * timing functions 00019 ***********************************************/ 00020 00021 int getTime(){ 00022 int time = timer.read_ms(); 00023 if(debug) print("getTime() = %d\r\n",time); 00024 return time; 00025 } 00026 00027 void markTime(){ 00028 if(debug) print("markTime()\r\n"); 00029 timer.start(); 00030 } 00031 00032 void sleep(float milliseconds){ 00033 if(debug) print("sleep(%f)\r\n",milliseconds); 00034 wait(milliseconds / 1000); 00035 } 00036 00037 /******************************** INPUTS AND OUTPUTS ********************************/ 00038 00039 void redLED(bool on){ 00040 if(debug) print("blueLED(%d) \r\n", on); 00041 setLED(!on, 1, 1); 00042 } 00043 00044 void greenLED(bool on){ 00045 if(debug) print("blueLED(%d) \r\n", on); 00046 setLED(1, !on, 1); 00047 } 00048 00049 void blueLED(bool on){ 00050 if(debug) print("blueLED(%d) \r\n", on); 00051 setLED(1, 1, !on); 00052 } 00053 00054 void setLED(float r, float g, float b){ 00055 rl.write(r); 00056 gl.write(g); 00057 bl.write(b); 00058 if(debug) print("setLED(%f,%f,%f) \r\n", r,g,b); 00059 } 00060 00061 void setDebug(bool _debug){ 00062 if(debug) print("setDebug()= %d\r\n", _debug); 00063 debug = _debug; 00064 } 00065 00066 00067 Accelerometer& getAccelerometer(){ 00068 return accelerometer; 00069 } 00070 00071 Serial getSerialPort(){ 00072 return port; 00073 } 00074 00075 00076 /************************************************ 00077 * init/finish functions 00078 ***********************************************/ 00079 00080 00081 void init(){ 00082 _initialize(); 00083 markTime(); 00084 } 00085 00086 void finish(){ 00087 _finish(); 00088 }
Generated on Tue Jul 12 2022 20:26:16 by
1.7.2
