cleaned up and commented after demo day

Dependencies:   microbit

Revision:
2:4f3f5d2fec6b
Parent:
1:032b96b05e51
--- a/bit_board.cpp	Wed Jun 12 15:21:01 2019 +0000
+++ b/bit_board.cpp	Tue Jun 18 14:01:25 2019 +0000
@@ -40,14 +40,11 @@
 InterruptIn button1(BUTTON_A);
 InterruptIn button2(BUTTON_B);
 
-//InterruptIn key1(MICROBIT_PIN_P0);
-// Try to use external signal, rather than button a&b as keys
-
 BLE ble;
 KeyboardService *kbdServicePtr;
 
-static const char DEVICE_NAME[] = "bit:board wire loop";
-static const char SHORT_DEVICE_NAME[] = "kbd blue";
+static const char DEVICE_NAME[] = "bit:board potentiometer"; // this is the name displayed after connection
+static const char SHORT_DEVICE_NAME[] = "kbd red"; // this is the name on bluetooth advertise
 
 static void onDisconnect(const Gap::DisconnectionCallbackParams_t *params)
 {
@@ -87,32 +84,31 @@
 
 void send_more_stuff() {send_string("p"); wait(0.1);}
 
-void send_one(){
+void send_one(){ // send a char '1'
     inputReportData[0] = 0;
     inputReportData[2] = 0x1e;
-    kbdServicePtr->send(inputReportData); //key down event?
-    kbdServicePtr->send(emptyInputReportData); // key up event?
+    kbdServicePtr->send(inputReportData); //key down event
+    kbdServicePtr->send(emptyInputReportData); // key up event
     wait(0.1);
 }
 
-void send_zero(){// testing input from pins
+void send_zero(){// // send a char '2'
     inputReportData[0] = 0;
     inputReportData[2] = 0x27;
-    kbdServicePtr->send(inputReportData); //key down event?
-    kbdServicePtr->send(emptyInputReportData); // key up event?
+    kbdServicePtr->send(inputReportData); //key down event
+    kbdServicePtr->send(emptyInputReportData); // key up event
     wait(0.1);
 }
 
-void send_up(){// testing input from pins
+void send_up(){// send the up array key signal - you can't type this key as a character
     inputReportData[0] = 0;
     inputReportData[2] = 0x52;
-    kbdServicePtr->send(inputReportData); //key down event?
-    kbdServicePtr->send(emptyInputReportData); // key up event?
+    kbdServicePtr->send(inputReportData); //key down event
+    kbdServicePtr->send(emptyInputReportData); // key up event
     wait(0.1);
 }
 
-void send_down(){// testing input from pins
-   // kbdServicePtr->putc(DownArrow);
+void send_down(){// send the down array key signal - you can't type this key as a character
     inputReportData[0] = 0;
     inputReportData[2] = 0x51;
     kbdServicePtr->send(inputReportData);
@@ -120,7 +116,7 @@
     wait(0.1);
 }
 
-void send_left(){// testing input from pins
+void send_left(){
     inputReportData[0] = 0;
     inputReportData[2] = 0x50;
     kbdServicePtr->send(inputReportData);
@@ -128,7 +124,7 @@
     wait(0.1);
 }
 
-void send_right(){// testing input from pins
+void send_right(){
     inputReportData[0] = 0;
     inputReportData[2] = 0x4f;
     kbdServicePtr->send(inputReportData);
@@ -136,7 +132,7 @@
     wait(0.1);
 }
 
-void send_space(){// testing input from pins
+void send_space(){
     inputReportData[0] = 0;
     inputReportData[2] = 0x2c;
     kbdServicePtr->send(inputReportData);
@@ -144,14 +140,14 @@
     wait(0.1);
 }
 
-void send_delete(){// testing input from pins
+void send_delete(){
     inputReportData[0] = 0;
     inputReportData[2] = 0x2a;
     kbdServicePtr->send(inputReportData);
     kbdServicePtr->send(emptyInputReportData);
     wait(0.1);
 }
-void send_tab(){// testing input from pins
+void send_tab(){
     inputReportData[0] = 0;
     inputReportData[2] = 0x2b;
     kbdServicePtr->send(inputReportData);
@@ -159,7 +155,7 @@
     wait(0.1);
 }
 
-void send_return(){// testing input from pins
+void send_return(){
     inputReportData[0] = 0;
     inputReportData[2] = 0x28;
     kbdServicePtr->send(inputReportData);
@@ -173,12 +169,11 @@
 }
     
 
-DigitalIn touch1(MICROBIT_PIN_P13); // for the normal 4
+DigitalIn touch1(MICROBIT_PIN_P13); 
 DigitalIn touch2(MICROBIT_PIN_P14);
 DigitalIn touch3(MICROBIT_PIN_P15);
-DigitalIn touch4(MICROBIT_PIN_P16); // disable for wire loop example?
-InterruptIn touch0(MICROBIT_PIN_P8);//
-//DigitalIn touch0(MICROBIT_PIN_P8); // for wire loop example only
+DigitalIn touch4(MICROBIT_PIN_P16); 
+InterruptIn touch0(MICROBIT_PIN_P8);
 AnalogIn x_axis(MICROBIT_PIN_P1);
 AnalogIn y_axis(MICROBIT_PIN_P2);
 AnalogIn potentiometer(MICROBIT_PIN_P0);
@@ -208,9 +203,9 @@
     mode current_mode = empty;
     float value = potentiometer.read();
     
-    if (value < (float) 229/1024 ) {current_mode = empty;}
-    else if (value < (float) 307/1024) { current_mode = arithmetic;}
-    else if (value < (float) 522/1024) { current_mode = number;}
+    if (value < (float) 175/1024 ) {current_mode = empty;}
+    else if (value < (float) 276/1024) { current_mode = arithmetic;}
+    else if (value < (float) 487/1024) { current_mode = number;}
     else {current_mode = alphebet;}
     
     // need to update mode, depending on value
@@ -249,41 +244,34 @@
 
 void wire_loop_control(){
 //    if (touch0 == 1) {send_string("w");wait(0.1);}  // touch, need to stop timer as well
-    // ???somehow pin8 is active high, need to pull down????
     if (touch1 == 1) {send_string("x");wait(0.1);}  // start timer
     if (touch2 == 1) {send_string("y");wait(0.1);}  // stop timer
     if (touch3 == 1) {send_string("z");wait(0.1);}  // reset timer
-//    if (touch4 == 1) {send_string("w");wait(0.1);} 
- /// try to use interrup
 }
 
 void touched(){send_string("w");wait(0.1);}
 
 int main(){
-    //create_fiber(JoystickControl);
-//    create_fiber(BLE_fiber);
     Ticker heartbeat;
 
     touch0.fall(touched);
-    //button1.rise(send_one);
-//    button2.rise(send_zero);
-    button1.rise(send_stuff);
+    button1.rise(send_stuff);  // testing the ability to send string
     button2.rise(send_more_stuff);
 
     HID_DEBUG("initialising ticker\r\n");
 
-    heartbeat.attach(waiting, 1);
+    heartbeat.attach(waiting, 1); // led indicator
 
     HID_DEBUG("initialising ble\r\n");
     ble.init();
 
-    ble.gap().onDisconnection(onDisconnect);
-    ble.gap().onConnection(onConnect);
+    ble.gap().onDisconnection(onDisconnect); // define behaviour when connection is lost
+    ble.gap().onConnection(onConnect);// define behaviour when connection is made
 
     initializeSecurity(ble);
 
     HID_DEBUG("adding hid service\r\n");
-    KeyboardService kbdService(ble);
+    KeyboardService kbdService(ble); // declare keyboard service
     kbdServicePtr = &kbdService;
 
     HID_DEBUG("adding device info and battery service\r\n");
@@ -303,14 +291,12 @@
     while (true) {
         ble.waitForEvent();  
         
-        //JoystickControl();  
+        JoystickControl();  
         
-        // normally, only realize one example: crossy road, potentiometer, or wire loop
-//        crossy_road_touch();
-//        potentiometer_control();
-        wire_loop_control();
+        potentiometer_control(); // example 1
+        
+//        wire_loop_control(); // example 2
     }
-//    release_fiber();
 }