lab5

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
csggreen
Date:
Fri Nov 24 04:12:38 2017 +0000
Commit message:
lab5

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 45c3dda8ec79 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Nov 24 04:12:38 2017 +0000
@@ -0,0 +1,65 @@
+
+#include "mbed.h"
+#include "MCP4922.h"
+
+MCP4922 MCP(SPI_MOSI, SPI_SCK,SPI_CS);  // MOSI, SCLK, CS
+
+
+/**** Main Function  ***/
+int main(void)
+{
+    MCP.frequency(1000000);
+    int gs = 0;
+    int i = 0;
+    uint8_t state1=0;
+    uint8_t state2=0;
+    
+    while(1) {
+        
+        if (gs==0){
+            if(i <= 745) {
+                i++;
+
+        } 
+            else {
+                i=0;
+                state1 = ~state1;
+        }
+
+            if(state1 ==0) {
+                MCP.writeA(i);
+        } 
+            else {
+                MCP.writeA(745-i);
+                if(745-i==0){
+                    gs=1;
+                    state1=0;
+                    i=0;
+                }
+        }
+            wait_us(1);
+    }
+        if(gs==1){
+            if(i<=745){
+                i++;
+            }
+            else {
+                i=0;
+                state2 = ~state2;
+        }
+            if(state2 ==0) {
+                MCP.writeA(1490-i);
+        } 
+            else {
+                MCP.writeA(i+745);
+                if(i==746){
+                    gs=0;
+                    state2=0;
+                    i=0;
+                }
+        }
+            wait_us(1);
+    }
+}
+
+}
\ No newline at end of file
diff -r 000000000000 -r 45c3dda8ec79 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Nov 24 04:12:38 2017 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/e7ca05fa8600
\ No newline at end of file