Ghost Mouse / Mbed 2 deprecated ghost_mouse

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
daviwang
Date:
Fri Mar 31 19:22:14 2017 +0000
Parent:
0:1c15cf9cc4f9
Child:
2:f501e506d62b
Commit message:
first version - setup done;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Mar 31 17:15:03 2017 +0000
+++ b/main.cpp	Fri Mar 31 19:22:14 2017 +0000
@@ -1,12 +1,66 @@
 #include "mbed.h"
 
 DigitalOut myled(LED1);
+Serial pc(USBTX, USBRX);
+
+I2C camera1(p9, p10);
+
+int IRsensorAddress = 0xB0;
+int slaveAddress;
+char data_buf[16];
+int i;
+
+
+//sensitivity
+//Level 5: p0 = 0x96, p1 = 0xFE, p2 = 0xFE, p3 = 0x05
+int sen0 = 0x96;
+int sen1 = 0xFE;
+int sen2 = 0xFE;
+int sen3 = 0x00;
+
+
+int Ix[4];
+int Iy[4];
+int s;
+
+void write2bytes(char data1, char data2){
+    char out[2];
+    out[0] = data1;
+    out[1] = data2;
+    camera1.write(slaveAddress, out, 2);
+    wait(0.01);   
+}
+
+void initCamera(void){
+  // Initialize WiiMote Camera
+    write2bytes(0x30, 0x01); 
+    write2bytes(0x00, 0x02); 
+    write2bytes(0x00, 0x00); 
+    write2bytes(0x71, 0x01); 
+    write2bytes(0x00, sen0); 
+    write2bytes(0x07, 0x00); 
+    write2bytes(sen1, 0x1A);
+    write2bytes(sen2, sen3); 
+    write2bytes(0x33, 0x03); 
+    write2bytes(0x30, 0x08);
+    wait(0.1);
+
+}
 
 int main() {
+    myled = 0;
+    slaveAddress = IRsensorAddress >> 1;
+    initCamera();
+    
+    
     while(1) {
-        myled = 1;
+        myled = myled - 1;
+        char out[1];
+        out[0] = 0x36;
+        
+        camera1.write(slaveAddress, out, 1);
+        
         wait(0.2);
-        myled = 0;
-        wait(0.2);
+        
     }
 }