ORTP-L Sensor Test

Dependencies:   Motordriver RIT mbed

Committer:
passionvirus
Date:
Thu Mar 28 12:20:24 2013 +0000
Revision:
0:ced7b365b52d
init;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
passionvirus 0:ced7b365b52d 1 #include "mbed.h"
passionvirus 0:ced7b365b52d 2 #include "motordriver.h"
passionvirus 0:ced7b365b52d 3 #include "RIT.h"
passionvirus 0:ced7b365b52d 4
passionvirus 0:ced7b365b52d 5 AnalogIn L_IR1(p15); // Analog In Pin
passionvirus 0:ced7b365b52d 6 AnalogIn L_IR2(p16); // Analog In Pin
passionvirus 0:ced7b365b52d 7 AnalogIn L_IR3(p17); // Analog In Pin
passionvirus 0:ced7b365b52d 8 AnalogIn R_IR3(p18); // Analog In Pin
passionvirus 0:ced7b365b52d 9 AnalogIn R_IR2(p19); // Analog In Pin
passionvirus 0:ced7b365b52d 10 AnalogIn R_IR1(p20); // Analog In Pin
passionvirus 0:ced7b365b52d 11
passionvirus 0:ced7b365b52d 12 DigitalOut LLED(p7); // Digital Out Pin
passionvirus 0:ced7b365b52d 13 DigitalOut RLED(p8);
passionvirus 0:ced7b365b52d 14
passionvirus 0:ced7b365b52d 15 DigitalOut L_IRLED1(p9); // Digital Out Pin
passionvirus 0:ced7b365b52d 16 DigitalOut L_IRLED2(p10); // Digital Out Pin
passionvirus 0:ced7b365b52d 17 DigitalOut L_IRLED3(p11); // Digital Out Pin
passionvirus 0:ced7b365b52d 18 DigitalOut R_IRLED3(p12); // Digital Out Pin
passionvirus 0:ced7b365b52d 19 DigitalOut R_IRLED2(p13); // Digital Out Pin
passionvirus 0:ced7b365b52d 20 DigitalOut R_IRLED1(p14); // Digital Out Pin
passionvirus 0:ced7b365b52d 21
passionvirus 0:ced7b365b52d 22 Serial serial(USBTX,USBRX); // Tx, Rx Pin
passionvirus 0:ced7b365b52d 23
passionvirus 0:ced7b365b52d 24 volatile uint32_t rithits = 0; //timer1 stops when timer1hits==imer1loop
passionvirus 0:ced7b365b52d 25
passionvirus 0:ced7b365b52d 26 Timer rit_timing;
passionvirus 0:ced7b365b52d 27
passionvirus 0:ced7b365b52d 28 void RIT_IRQHandler(void)
passionvirus 0:ced7b365b52d 29 {
passionvirus 0:ced7b365b52d 30 //Flash Led.
passionvirus 0:ced7b365b52d 31 L_IRLED1=!L_IRLED1;
passionvirus 0:ced7b365b52d 32 L_IRLED2=!L_IRLED2;
passionvirus 0:ced7b365b52d 33 L_IRLED3=!L_IRLED3;
passionvirus 0:ced7b365b52d 34 R_IRLED3=!R_IRLED3;
passionvirus 0:ced7b365b52d 35 R_IRLED2=!R_IRLED2;
passionvirus 0:ced7b365b52d 36 R_IRLED1=!R_IRLED1;
passionvirus 0:ced7b365b52d 37
passionvirus 0:ced7b365b52d 38 //Count Hits.
passionvirus 0:ced7b365b52d 39 rithits++;
passionvirus 0:ced7b365b52d 40 }
passionvirus 0:ced7b365b52d 41
passionvirus 0:ced7b365b52d 42 RIT rit(1); //10ms
passionvirus 0:ced7b365b52d 43
passionvirus 0:ced7b365b52d 44 int main()
passionvirus 0:ced7b365b52d 45 {
passionvirus 0:ced7b365b52d 46 LLED=1;
passionvirus 0:ced7b365b52d 47 RLED=1; // LED Init
passionvirus 0:ced7b365b52d 48 int data[6];
passionvirus 0:ced7b365b52d 49 serial.baud(115200);
passionvirus 0:ced7b365b52d 50 rit.setup_us(10);
passionvirus 0:ced7b365b52d 51
passionvirus 0:ced7b365b52d 52 rit.append(RIT_IRQHandler);
passionvirus 0:ced7b365b52d 53
passionvirus 0:ced7b365b52d 54 rit_timing.start();
passionvirus 0:ced7b365b52d 55 rit.enable();
passionvirus 0:ced7b365b52d 56
passionvirus 0:ced7b365b52d 57 while(1)
passionvirus 0:ced7b365b52d 58 {
passionvirus 0:ced7b365b52d 59 data[0] = L_IR1 * 100; // ain (0.0 ~ 1.0)
passionvirus 0:ced7b365b52d 60 data[1] = L_IR2 * 100; // ain (0.0 ~ 1.0)
passionvirus 0:ced7b365b52d 61 data[2] = L_IR3 * 100; // ain (0.0 ~ 1.0)
passionvirus 0:ced7b365b52d 62 data[3] = R_IR3 * 100; // ain (0.0 ~ 1.0)
passionvirus 0:ced7b365b52d 63 data[4] = R_IR2 * 100; // ain (0.0 ~ 1.0)
passionvirus 0:ced7b365b52d 64 data[5] = R_IR1 * 100; // ain (0.0 ~ 1.0)
passionvirus 0:ced7b365b52d 65
passionvirus 0:ced7b365b52d 66 serial.printf("| %03d | %03d | %03d | %03d | %03d | %03d |\n", data[0], data[1], data[2], data[3], data[4], data[5]); // mbed -> PC, data(0~100)
passionvirus 0:ced7b365b52d 67 }
passionvirus 0:ced7b365b52d 68
passionvirus 0:ced7b365b52d 69 rit.unappend();
passionvirus 0:ced7b365b52d 70 rit.append(RIT_IRQHandler);
passionvirus 0:ced7b365b52d 71 rit.disable();
passionvirus 0:ced7b365b52d 72 rit_timing.stop();
passionvirus 0:ced7b365b52d 73
passionvirus 0:ced7b365b52d 74 rit_timing.start();
passionvirus 0:ced7b365b52d 75 rit.enable();
passionvirus 0:ced7b365b52d 76 }