Example controlling galvanomirrors (X and Y) using the spi DAC MCP4922 and the new platform FRDM_K64F

Dependencies:   mbed

Committer:
mbedalvaro
Date:
Sun May 25 11:28:28 2014 +0000
Revision:
0:26b228dde70c
Child:
1:4be6abc4ed43
first commit, program compiles but yet not tried on the mbed;

Who changed what in which revision?

UserRevisionLine numberNew 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 0:26b228dde70c 11 int main() {
mbedalvaro 0:26b228dde70c 12
mbedalvaro 0:26b228dde70c 13 // SETUP: --------------------------------------------------------------------------------------------
mbedalvaro 0:26b228dde70c 14 IO.init(); // note: serial speed can be changed by checking in the hardwareIO.cpp initialization
mbedalvaro 0:26b228dde70c 15
mbedalvaro 0:26b228dde70c 16 // Set displaying laser powers:
mbedalvaro 0:26b228dde70c 17 IO.setRedPower(1);//turn on the red (displaying) laser
mbedalvaro 0:26b228dde70c 18 IO.setGreenPower(0);
mbedalvaro 0:26b228dde70c 19 IO.setBluePower(0);
mbedalvaro 0:26b228dde70c 20
mbedalvaro 0:26b228dde70c 21 wait_ms(100);
mbedalvaro 0:26b228dde70c 22
mbedalvaro 0:26b228dde70c 23 Y = CENTER_AD_MIRROR_X;
mbedalvaro 0:26b228dde70c 24 X = CENTER_AD_MIRROR_Y;
mbedalvaro 0:26b228dde70c 25 IO.writeOutXY(X,Y);
mbedalvaro 0:26b228dde70c 26
mbedalvaro 0:26b228dde70c 27 // MAIN LOOP: --------------------------------------------------------------------------------------------
mbedalvaro 0:26b228dde70c 28 while(1) {
mbedalvaro 0:26b228dde70c 29 processSerial();
mbedalvaro 0:26b228dde70c 30 if (newPositionReady) {
mbedalvaro 0:26b228dde70c 31 IO.writeOutXY(X,Y);
mbedalvaro 0:26b228dde70c 32 newPositionReady=false;
mbedalvaro 0:26b228dde70c 33 }
mbedalvaro 0:26b228dde70c 34 }
mbedalvaro 0:26b228dde70c 35 }
mbedalvaro 0:26b228dde70c 36
mbedalvaro 0:26b228dde70c 37 // --------------------------------------------------------------------------------------------
mbedalvaro 0:26b228dde70c 38 // String to store ALPHANUMERIC DATA (i.e., integers, floating point numbers, unsigned ints, etc represented as DEC) sent wirelessly:
mbedalvaro 0:26b228dde70c 39 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 40 int indexStringData=0;//position of the byte in the string
mbedalvaro 0:26b228dde70c 41
mbedalvaro 0:26b228dde70c 42 void processSerial() {
mbedalvaro 0:26b228dde70c 43 myled=0;
mbedalvaro 0:26b228dde70c 44 while(pc.readable()>0){
mbedalvaro 0:26b228dde70c 45 myled=1;
mbedalvaro 0:26b228dde70c 46
mbedalvaro 0:26b228dde70c 47 char val =pc.getc();
mbedalvaro 0:26b228dde70c 48
mbedalvaro 0:26b228dde70c 49 // Save ASCII numeric characters (ASCII 0 - 9) on stringData:
mbedalvaro 0:26b228dde70c 50 if ((val >= '0') && (val <= '9')){ // this is 45 to 57 (included)
mbedalvaro 0:26b228dde70c 51 stringData[indexStringData] = val;
mbedalvaro 0:26b228dde70c 52 indexStringData++;
mbedalvaro 0:26b228dde70c 53 }
mbedalvaro 0:26b228dde70c 54
mbedalvaro 0:26b228dde70c 55 // X value?
mbedalvaro 0:26b228dde70c 56 else if (val=='X') {
mbedalvaro 0:26b228dde70c 57 stringData[indexStringData] = 0 ;
mbedalvaro 0:26b228dde70c 58 X=atoi(stringData);
mbedalvaro 0:26b228dde70c 59 indexStringData=0;
mbedalvaro 0:26b228dde70c 60 }
mbedalvaro 0:26b228dde70c 61
mbedalvaro 0:26b228dde70c 62 // Y value?
mbedalvaro 0:26b228dde70c 63 else if (val=='Y') {
mbedalvaro 0:26b228dde70c 64 stringData[indexStringData] = 0 ;
mbedalvaro 0:26b228dde70c 65 X=atoi(stringData);
mbedalvaro 0:26b228dde70c 66 indexStringData=0;
mbedalvaro 0:26b228dde70c 67 newPositionReady=true;
mbedalvaro 0:26b228dde70c 68 }
mbedalvaro 0:26b228dde70c 69
mbedalvaro 0:26b228dde70c 70 }
mbedalvaro 0:26b228dde70c 71 }