sotsuron

Fork of linearMirrorMotion1017 by Hiromasa Oku

Committer:
mbedalvaro
Date:
Fri Sep 07 08:04:40 2012 +0000
Revision:
1:daf6b4939120
Parent:
0:4e12dea53fbe
Child:
2:0548c7bf9fba
updated library;

Who changed what in which revision?

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