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-25
- Revision:
- 0:26b228dde70c
- Child:
- 1:4be6abc4ed43
File content as of revision 0:26b228dde70c:
#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; 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) { processSerial(); if (newPositionReady) { IO.writeOutXY(X,Y); 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() { myled=0; while(pc.readable()>0){ myled=1; 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 ; X=atoi(stringData); indexStringData=0; newPositionReady=true; } } }