![](/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
main.cpp@3:89f592efbe84, 2014-06-04 (annotated)
- Committer:
- mbedalvaro
- Date:
- Wed Jun 04 09:47:04 2014 +0000
- Revision:
- 3:89f592efbe84
- Parent:
- 2:383b2acec6e4
- Child:
- 4:1428775752f7
seems working. I had to change the modulating pin D8 to D5, because as PWM output the pin D8 seems not to reach 0...
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedalvaro | 0:26b228dde70c | 1 | #include "mbed.h" |
mbedalvaro | 0:26b228dde70c | 2 | #include "laserProjectorHardware.h" |
mbedalvaro | 0:26b228dde70c | 3 | |
mbedalvaro | 0:26b228dde70c | 4 | DigitalOut myled(LED3); |
mbedalvaro | 0:26b228dde70c | 5 | |
mbedalvaro | 0:26b228dde70c | 6 | void processSerial(); |
mbedalvaro | 0:26b228dde70c | 7 | |
mbedalvaro | 0:26b228dde70c | 8 | unsigned int X, Y; // position of the mirrors (note: in fact, azimuth and elevation) |
mbedalvaro | 0:26b228dde70c | 9 | bool newPositionReady=false; |
mbedalvaro | 0:26b228dde70c | 10 | |
mbedalvaro | 2:383b2acec6e4 | 11 | unsigned long counter=0; |
mbedalvaro | 2:383b2acec6e4 | 12 | |
mbedalvaro | 0:26b228dde70c | 13 | int main() { |
mbedalvaro | 0:26b228dde70c | 14 | |
mbedalvaro | 0:26b228dde70c | 15 | // SETUP: -------------------------------------------------------------------------------------------- |
mbedalvaro | 0:26b228dde70c | 16 | IO.init(); // note: serial speed can be changed by checking in the hardwareIO.cpp initialization |
mbedalvaro | 0:26b228dde70c | 17 | |
mbedalvaro | 0:26b228dde70c | 18 | wait_ms(100); |
mbedalvaro | 0:26b228dde70c | 19 | |
mbedalvaro | 0:26b228dde70c | 20 | Y = CENTER_AD_MIRROR_X; |
mbedalvaro | 0:26b228dde70c | 21 | X = CENTER_AD_MIRROR_Y; |
mbedalvaro | 0:26b228dde70c | 22 | IO.writeOutXY(X,Y); |
mbedalvaro | 0:26b228dde70c | 23 | |
mbedalvaro | 0:26b228dde70c | 24 | // MAIN LOOP: -------------------------------------------------------------------------------------------- |
mbedalvaro | 1:4be6abc4ed43 | 25 | while(1) { |
mbedalvaro | 1:4be6abc4ed43 | 26 | |
mbedalvaro | 1:4be6abc4ed43 | 27 | // myled=0;IO.setRedPower(1); |
mbedalvaro | 1:4be6abc4ed43 | 28 | // wait_ms(1000); |
mbedalvaro | 1:4be6abc4ed43 | 29 | // myled=1;IO.setRedPower(0); |
mbedalvaro | 1:4be6abc4ed43 | 30 | // wait_ms(1000); |
mbedalvaro | 1:4be6abc4ed43 | 31 | |
mbedalvaro | 2:383b2acec6e4 | 32 | // Y = CENTER_AD_MIRROR_X+1000*cos(1.0*counter/10); |
mbedalvaro | 2:383b2acec6e4 | 33 | // X = CENTER_AD_MIRROR_Y+800*sin(1.0*counter/15); |
mbedalvaro | 2:383b2acec6e4 | 34 | // IO.writeOutXY(X,Y); |
mbedalvaro | 2:383b2acec6e4 | 35 | // counter++; |
mbedalvaro | 2:383b2acec6e4 | 36 | |
mbedalvaro | 2:383b2acec6e4 | 37 | |
mbedalvaro | 2:383b2acec6e4 | 38 | //IO.drawCircle(X, Y, 1000, 200); |
mbedalvaro | 2:383b2acec6e4 | 39 | |
mbedalvaro | 0:26b228dde70c | 40 | processSerial(); |
mbedalvaro | 0:26b228dde70c | 41 | if (newPositionReady) { |
mbedalvaro | 2:383b2acec6e4 | 42 | IO.writeOutXY(X,Y); |
mbedalvaro | 2:383b2acec6e4 | 43 | //IO.drawCircle(X, Y, 1000, 20); |
mbedalvaro | 0:26b228dde70c | 44 | newPositionReady=false; |
mbedalvaro | 0:26b228dde70c | 45 | } |
mbedalvaro | 0:26b228dde70c | 46 | } |
mbedalvaro | 0:26b228dde70c | 47 | } |
mbedalvaro | 0:26b228dde70c | 48 | |
mbedalvaro | 0:26b228dde70c | 49 | // -------------------------------------------------------------------------------------------- |
mbedalvaro | 0:26b228dde70c | 50 | // String to store ALPHANUMERIC DATA (i.e., integers, floating point numbers, unsigned ints, etc represented as DEC) sent wirelessly: |
mbedalvaro | 0:26b228dde70c | 51 | 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... |
mbedalvaro | 0:26b228dde70c | 52 | int indexStringData=0;//position of the byte in the string |
mbedalvaro | 0:26b228dde70c | 53 | |
mbedalvaro | 0:26b228dde70c | 54 | void processSerial() { |
mbedalvaro | 1:4be6abc4ed43 | 55 | |
mbedalvaro | 1:4be6abc4ed43 | 56 | while(pc.readable()>0) { |
mbedalvaro | 1:4be6abc4ed43 | 57 | |
mbedalvaro | 0:26b228dde70c | 58 | |
mbedalvaro | 0:26b228dde70c | 59 | char val =pc.getc(); |
mbedalvaro | 0:26b228dde70c | 60 | |
mbedalvaro | 0:26b228dde70c | 61 | // Save ASCII numeric characters (ASCII 0 - 9) on stringData: |
mbedalvaro | 0:26b228dde70c | 62 | if ((val >= '0') && (val <= '9')){ // this is 45 to 57 (included) |
mbedalvaro | 0:26b228dde70c | 63 | stringData[indexStringData] = val; |
mbedalvaro | 0:26b228dde70c | 64 | indexStringData++; |
mbedalvaro | 1:4be6abc4ed43 | 65 | |
mbedalvaro | 0:26b228dde70c | 66 | } |
mbedalvaro | 0:26b228dde70c | 67 | |
mbedalvaro | 0:26b228dde70c | 68 | // X value? |
mbedalvaro | 0:26b228dde70c | 69 | else if (val=='X') { |
mbedalvaro | 0:26b228dde70c | 70 | stringData[indexStringData] = 0 ; |
mbedalvaro | 0:26b228dde70c | 71 | X=atoi(stringData); |
mbedalvaro | 0:26b228dde70c | 72 | indexStringData=0; |
mbedalvaro | 0:26b228dde70c | 73 | } |
mbedalvaro | 0:26b228dde70c | 74 | |
mbedalvaro | 0:26b228dde70c | 75 | // Y value? |
mbedalvaro | 0:26b228dde70c | 76 | else if (val=='Y') { |
mbedalvaro | 0:26b228dde70c | 77 | stringData[indexStringData] = 0 ; |
mbedalvaro | 1:4be6abc4ed43 | 78 | Y=atoi(stringData); |
mbedalvaro | 0:26b228dde70c | 79 | indexStringData=0; |
mbedalvaro | 0:26b228dde70c | 80 | newPositionReady=true; |
mbedalvaro | 0:26b228dde70c | 81 | } |
mbedalvaro | 1:4be6abc4ed43 | 82 | |
mbedalvaro | 1:4be6abc4ed43 | 83 | else if (val=='L') { |
mbedalvaro | 1:4be6abc4ed43 | 84 | stringData[indexStringData] = 0 ; |
mbedalvaro | 3:89f592efbe84 | 85 | //if(atoi(stringData)>0) IO.setRedPower(1); else IO.setRedPower(0); |
mbedalvaro | 3:89f592efbe84 | 86 | if(atoi(stringData)>0) IO.setLockinPower(1); else IO.setLockinPower(0); // for the time being, we only use the lockin laser |
mbedalvaro | 1:4be6abc4ed43 | 87 | indexStringData=0; |
mbedalvaro | 1:4be6abc4ed43 | 88 | } |
mbedalvaro | 0:26b228dde70c | 89 | |
mbedalvaro | 2:383b2acec6e4 | 90 | else if (val=='S') { |
mbedalvaro | 2:383b2acec6e4 | 91 | stringData[indexStringData] = 0 ; |
mbedalvaro | 2:383b2acec6e4 | 92 | IO.showLimitsMirrors(int(atoi(stringData))); |
mbedalvaro | 2:383b2acec6e4 | 93 | indexStringData=0; |
mbedalvaro | 2:383b2acec6e4 | 94 | } |
mbedalvaro | 2:383b2acec6e4 | 95 | |
mbedalvaro | 0:26b228dde70c | 96 | } |
mbedalvaro | 0:26b228dde70c | 97 | } |