a

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
lolopo008
Date:
Sat Dec 05 06:36:43 2015 +0000
Commit message:
a

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 6fac2f739171 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Dec 05 06:36:43 2015 +0000
@@ -0,0 +1,185 @@
+#include "mbed.h"
+
+SPI DataPack(SPI_MOSI, SPI_MISO, SPI_SCK);
+DigitalOut Latch(D10);
+AnalogIn VR0(A0);
+AnalogIn VR1(A1);
+Serial pc(USBTX, USBRX);
+
+float VR_value0,VR_value1;
+int Row[8]= {1,2,4,8,16,32,64,128};
+int Col[8]= {254,253,251,247,239,223,191,127};
+int x;
+
+void Player1()
+{
+    VR_value0 = VR0.read();
+    VR_value0 = VR_value0*6;
+
+    Latch=0;
+    if(VR_value0<=1) {
+        //D1
+        DataPack.write(0xFF);
+        wait_us(1);
+        DataPack.write(0x1F);
+        wait_us(1);
+        DataPack.write(0xFF);
+        wait_us(1);
+        DataPack.write(0x01);
+        wait_us(1);
+    } else if(VR_value0>1&&VR_value0<=2) {
+        //D2
+        DataPack.write(0xFF);
+        wait_us(1);
+        DataPack.write(0x8F);
+        wait_us(1);
+        DataPack.write(0xFF);
+        wait_us(1);
+        DataPack.write(0x01);
+        wait_us(1);
+    } else if(VR_value0>2&&VR_value0<=3) {
+        //D3
+        DataPack.write(0xFF);
+        wait_us(1);
+        DataPack.write(0xC7);
+        wait_us(1);
+        DataPack.write(0xFF);
+        wait_us(1);
+        DataPack.write(0x01);
+        wait_us(1);
+    } else if(VR_value0>3&&VR_value0<=4) {
+        //D4
+        DataPack.write(0xFF);
+        wait_us(1);
+        DataPack.write(0xE3);
+        wait_us(1);
+        DataPack.write(0xFF);
+        wait_us(1);
+        DataPack.write(0x01);
+        wait_us(1);
+    } else if(VR_value0>4&&VR_value0<=5) {
+        //D5
+        DataPack.write(0xFF);
+        wait_us(1);
+        DataPack.write(0xF1);
+        wait_us(1);
+        DataPack.write(0xFF);
+        wait_us(1);
+        DataPack.write(0x01);
+        wait_us(1);
+    } else if(VR_value0>5&&VR_value0<=6) {
+        //D6
+        DataPack.write(0xFF);
+        wait_us(1);
+        DataPack.write(0xF8);
+        wait_us(1);
+        DataPack.write(0xFF);
+        wait_us(1);
+        DataPack.write(0x01);
+        wait_us(1);
+    }
+    Latch=1;
+}
+
+void Player2()
+{
+    VR_value1 = VR1.read();
+    VR_value1 = VR_value1*6;
+
+    Latch=0;
+    if(VR_value1<=1) {
+        //U1
+        DataPack.write(0xFF);
+        wait_us(1);
+        DataPack.write(0x1F);
+        wait_us(1);
+        DataPack.write(0xFF);
+        wait_us(1);
+        DataPack.write(0x80);
+        wait_us(1);
+    } else if(VR_value1>1&&VR_value1<=2) {
+        //U2
+        DataPack.write(0xFF);
+        wait_us(1);
+        DataPack.write(0x8F);
+        wait_us(1);
+        DataPack.write(0xFF);
+        wait_us(1);
+        DataPack.write(0x80);
+        wait_us(1);
+    } else if(VR_value0>2&&VR_value0<=3) {
+        //U3
+        DataPack.write(0xFF);
+        wait_us(1);
+        DataPack.write(0xC7);
+        wait_us(1);
+        DataPack.write(0xFF);
+        wait_us(1);
+        DataPack.write(0x80);
+        wait_us(1);
+    } else if(VR_value1>3&&VR_value1<=4) {
+        //U4
+        DataPack.write(0xFF);
+        wait_us(1);
+        DataPack.write(0xE3);
+        wait_us(1);
+        DataPack.write(0xFF);
+        wait_us(1);
+        DataPack.write(0x80);
+        wait_us(1);
+    } else if(VR_value1>4&&VR_value1<=5) {
+        //U5
+        DataPack.write(0xFF);
+        wait_us(1);
+        DataPack.write(0xF1);
+        wait_us(1);
+        DataPack.write(0xFF);
+        wait_us(1);
+        DataPack.write(0x80);
+        wait_us(1);
+    } else if(VR_value1>5&&VR_value1<=6) {
+        //U6
+        DataPack.write(0xFF);
+        wait_us(1);
+        DataPack.write(0xF8);
+        wait_us(1);
+        DataPack.write(0xFF);
+        wait_us(1);
+        DataPack.write(0x80);
+        wait_us(1);
+    }
+    Latch=1;
+}
+
+int main()
+{
+    DataPack.frequency(100000);
+    DataPack.format(8,0);
+
+    while(1) {
+        Player1();
+        Player2();
+
+        Latch=0;
+        DataPack.write(0xFF);
+        wait_us(1);
+        DataPack.write(0xF8);
+        wait_us(1);
+        DataPack.write(0xF8);
+        wait_us(1);
+        DataPack.write(0x2A);
+        wait_us(1);
+        Latch=1;
+        
+        Latch=0;
+        DataPack.write(0xFF);
+        wait_us(1);
+        DataPack.write(0xFE);
+        wait_us(1);
+        DataPack.write(0xFE);
+        wait_us(1);
+        DataPack.write(0x14);
+        wait_us(1);
+        Latch=1;
+    }
+}
diff -r 000000000000 -r 6fac2f739171 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Dec 05 06:36:43 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9296ab0bfc11
\ No newline at end of file