UT CS Bootcamp code for creating a secret knock

Dependencies:   MMA8451Q mbed tsi_sensor

Fork of UTCSBootcamp by Clare Coleman

Files at this revision

API Documentation at this revision

Comitter:
parnell
Date:
Fri Aug 22 19:52:08 2014 +0000
Parent:
10:351ba1920e42
Commit message:
Revised with touch sensor;

Changed in this revision

Includes/KnockBaseAPI.h Show annotated file Show diff for this revision Revisions of this file
KnockAPI.cpp Show annotated file Show diff for this revision Revisions of this file
KnockAPI.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
diff -r 351ba1920e42 -r 0ac08d8a296f Includes/KnockBaseAPI.h
--- a/Includes/KnockBaseAPI.h	Thu Aug 21 19:48:43 2014 +0000
+++ b/Includes/KnockBaseAPI.h	Fri Aug 22 19:52:08 2014 +0000
@@ -3,11 +3,13 @@
 
 #include <stdarg.h>
 #include <MMA8451Q.h>   // accelerometer
+#include "tsi_sensor.h"
 
 Serial port(USBTX,USBRX);
 
 #define MMA8451_I2C_ADDRESS (0x1d<<1)
 
+//http://mbed.org/users/wd5gnr/code/frdm_tsi_slider_led_blend/rev/ (tsi example)
 MMA8451Q accelerometer(PTE25,PTE24, MMA8451_I2C_ADDRESS);
 
 float turnOffset = 0.0;// the turn turnOffset
diff -r 351ba1920e42 -r 0ac08d8a296f KnockAPI.cpp
--- a/KnockAPI.cpp	Thu Aug 21 19:48:43 2014 +0000
+++ b/KnockAPI.cpp	Fri Aug 22 19:52:08 2014 +0000
@@ -37,42 +37,25 @@
 /******************************** INPUTS AND OUTPUTS ********************************/
 
 void redLED(bool on){
-    redLED(on, true);
+    if(debug) print("blueLED(%d) \r\n", on);
+    setLED(!on, 1, 1);
 }
 
 void greenLED(bool on){
-    greenLED(on, true);
+    if(debug) print("blueLED(%d) \r\n", on);
+    setLED(1, !on, 1);
 }
 
 void blueLED(bool on){
-    blueLED(on, true);
-}
-
-void redLED(bool on, bool turnOffOtherColors){
-    if (turnOffOtherColors){
-        gl.write(1);
-        bl.write(1);
-    }
-    rl.write(!on);
-    if(debug) print("redLED(%d) \r\n", on);
+    if(debug) print("blueLED(%d) \r\n", on);
+    setLED(1, 1, !on);
 }
 
-void greenLED(bool on, bool turnOffOtherColors){
-    if (turnOffOtherColors){
-        rl.write(1);
-        bl.write(1);
-    }
-    gl.write(!on);
-    if(debug) print("greenLED(%d)\r\n", on);
-}
-
-void blueLED(bool on, bool turnOffOtherColors){
-    if (turnOffOtherColors){
-        rl.write(1);
-        gl.write(1);
-    }
-    bl.write(!on);
-    if(debug) print("blueLED(%d) \r\n", on);
+void setLED(float r, float g, float b){
+    rl.write(r);
+    gl.write(g);
+    bl.write(b);
+    if(debug) print("setLED(%f,%f,%f) \r\n", r,g,b);
 }
 
 void setDebug(bool _debug){
@@ -81,7 +64,7 @@
 }
 
 
-Accelerometer getAccelerometer(){
+Accelerometer& getAccelerometer(){
     return accelerometer;
 }
 
diff -r 351ba1920e42 -r 0ac08d8a296f KnockAPI.h
--- a/KnockAPI.h	Thu Aug 21 19:48:43 2014 +0000
+++ b/KnockAPI.h	Fri Aug 22 19:52:08 2014 +0000
@@ -2,8 +2,10 @@
 #ifndef KNOCK_API_0yx22l34755
 #define KNOCK_API_0yx22l34755
 #include <MMA8451Q.h>
+#include "tsi_sensor.h"
 
 typedef MMA8451Q Accelerometer;
+typedef TSIAnalogSlider TouchSensor;
 
 /******************************** Init and Finish ********************************/
 void init();
@@ -49,29 +51,12 @@
   */
 void blueLED(bool on);
 
-/** turn on/off red led
-  * @param on: true to turn on, false to turn off
-  * @param turnOffOtherColors: 
-        true to only turn on/off this color, 
-        false to allow color mixing with other colors
+/** turn on/off blue led
+  * @param red: amount of red , from 0 to 1
+  * @param green: amount of red , from 0 to 1
+  * @param blue: amount of red , from 0 to 1
   */
-void redLED(bool on, bool turnOffOtherColors);
-    
-/** turn on/off green led
-  * @param on: true to turn on, false to turn off
-  * @param turnOffOtherColors: 
-        true to only turn on/off this color, 
-        false to allow color mixing with other colors
-  */
-void greenLED(bool on, bool turnOffOtherColors);
-    
-/** turn on/off blue led
-  * @param on: true to turn on, false to turn off
-  * @param turnOffOtherColors: 
-        true to only turn on/off this color, 
-        false to allow color mixing with other colors
-  */
-void blueLED(bool on, bool turnOffOtherColors);
+void setLED(float red, float green, float blue);
 
 /** Turn on debugging. Prints each method call to the serial port.
   * @param _debug True to turn on debugging, false to turn it off.
@@ -80,8 +65,13 @@
 
 
 /** Get the Accelerometer object
+        Code for the accelerometer can be found in MMA8451Q.h
+        important functions
+        getAccX();
+        getAccY();
+        getAccZ();
   */
-Accelerometer getAccelerometer();
+Accelerometer& getAccelerometer();
 
 /** Get the Serial object to interface directly with the usb port
     Allows: getc, putc, printf, etc
diff -r 351ba1920e42 -r 0ac08d8a296f main.cpp
--- a/main.cpp	Thu Aug 21 19:48:43 2014 +0000
+++ b/main.cpp	Fri Aug 22 19:52:08 2014 +0000
@@ -1,11 +1,23 @@
 #include "mbed.h"       // mbed 
+//#include <stdarg.h>
 #include <MMA8451Q.h>   // accelerometer
 #include <stdlib.h>     // abs
 #include <math.h>       // sqrt
 #include "KnockAPI.h"   // our api
 
-int main() {
-    init(); /// call the base inits
+#define ELEC0 9
+#define ELEC1 10
+/** Get the TouchSensor object
+        Code for the touch sensor can be found in tsi_sensor.h
+        important functions
+        readPercentage(); //returns where the "touch" is,
+            the touch is a value between [0 ... 1]
+            0 represents no touch, greater than 0 to 1 from left to right
+  */
+TSIAnalogSlider ts(ELEC0, ELEC1, 40);
+
+int main(void) {
+      init(); /// call the base inits
     /*  uncomment to see print traces from all API functions 
         (you will need to use your serial port for this) */
 //    setDebug(true); 
@@ -24,4 +36,4 @@
     }
 
     finish(); /// call the base finish
-}
+}
\ No newline at end of file