![](/media/cache/profiles/68a15b5278e4f7c4c056df9d5f1d3b1f.jpg.50x50_q85.jpg)
Example controlling galvanomirrors (X and Y) using the spi DAC MCP4922 and the new platform FRDM_K64F
Diff: main.cpp
- Revision:
- 1:4be6abc4ed43
- Parent:
- 0:26b228dde70c
- Child:
- 2:383b2acec6e4
--- a/main.cpp Sun May 25 11:28:28 2014 +0000 +++ b/main.cpp Sun May 25 12:24:21 2014 +0000 @@ -25,7 +25,13 @@ IO.writeOutXY(X,Y); // MAIN LOOP: -------------------------------------------------------------------------------------------- - while(1) { + while(1) { + + // myled=0;IO.setRedPower(1); + // wait_ms(1000); + // myled=1;IO.setRedPower(0); + // wait_ms(1000); + processSerial(); if (newPositionReady) { IO.writeOutXY(X,Y); @@ -40,9 +46,9 @@ int indexStringData=0;//position of the byte in the string void processSerial() { -myled=0; - while(pc.readable()>0){ - myled=1; + + while(pc.readable()>0) { + char val =pc.getc(); @@ -50,6 +56,7 @@ if ((val >= '0') && (val <= '9')){ // this is 45 to 57 (included) stringData[indexStringData] = val; indexStringData++; + } // X value? @@ -62,10 +69,16 @@ // Y value? else if (val=='Y') { stringData[indexStringData] = 0 ; - X=atoi(stringData); + Y=atoi(stringData); indexStringData=0; newPositionReady=true; } + + else if (val=='L') { + stringData[indexStringData] = 0 ; + if(atoi(stringData)>0) IO.setRedPower(1); else IO.setRedPower(0); + indexStringData=0; + } } } \ No newline at end of file