Alvaro Cassinelli
/
laserScannerControl_FRDMK64F
Example controlling galvanomirrors (X and Y) using the spi DAC MCP4922 and the new platform FRDM_K64F
main.cpp
- Committer:
- mbedalvaro
- Date:
- 2014-05-26
- Revision:
- 2:383b2acec6e4
- Parent:
- 1:4be6abc4ed43
- Child:
- 3:89f592efbe84
File content as of revision 2:383b2acec6e4:
#include "mbed.h" #include "laserProjectorHardware.h" DigitalOut myled(LED3); void processSerial(); unsigned int X, Y; // position of the mirrors (note: in fact, azimuth and elevation) bool newPositionReady=false; unsigned long counter=0; int main() { // SETUP: -------------------------------------------------------------------------------------------- IO.init(); // note: serial speed can be changed by checking in the hardwareIO.cpp initialization // Set displaying laser powers: IO.setRedPower(1);//turn on the red (displaying) laser IO.setGreenPower(0); IO.setBluePower(0); wait_ms(100); Y = CENTER_AD_MIRROR_X; X = CENTER_AD_MIRROR_Y; IO.writeOutXY(X,Y); // MAIN LOOP: -------------------------------------------------------------------------------------------- while(1) { // myled=0;IO.setRedPower(1); // wait_ms(1000); // myled=1;IO.setRedPower(0); // wait_ms(1000); // Y = CENTER_AD_MIRROR_X+1000*cos(1.0*counter/10); // X = CENTER_AD_MIRROR_Y+800*sin(1.0*counter/15); // IO.writeOutXY(X,Y); // counter++; //IO.drawCircle(X, Y, 1000, 200); processSerial(); if (newPositionReady) { IO.writeOutXY(X,Y); //IO.drawCircle(X, Y, 1000, 20); newPositionReady=false; } } } // -------------------------------------------------------------------------------------------- // String to store ALPHANUMERIC DATA (i.e., integers, floating point numbers, unsigned ints, etc represented as DEC) sent wirelessly: char stringData[24]; // note: an integer is two bytes long, represented with a maximum of 5 digits, but we may send floats or unsigned int... int indexStringData=0;//position of the byte in the string void processSerial() { while(pc.readable()>0) { char val =pc.getc(); // Save ASCII numeric characters (ASCII 0 - 9) on stringData: if ((val >= '0') && (val <= '9')){ // this is 45 to 57 (included) stringData[indexStringData] = val; indexStringData++; } // X value? else if (val=='X') { stringData[indexStringData] = 0 ; X=atoi(stringData); indexStringData=0; } // Y value? else if (val=='Y') { stringData[indexStringData] = 0 ; 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; } else if (val=='S') { stringData[indexStringData] = 0 ; IO.showLimitsMirrors(int(atoi(stringData))); indexStringData=0; } } }