Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of projet_accel by
Revision 1:761ea6f346ab, committed 2014-03-23
- Comitter:
- trixrabbit
- Date:
- Sun Mar 23 20:40:24 2014 +0000
- Parent:
- 0:1e7ffdb6d1db
- Commit message:
- 23 mars
Changed in this revision
collector.cpp | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/collector.cpp Thu Mar 20 13:16:01 2014 +0000 +++ b/collector.cpp Sun Mar 23 20:40:24 2014 +0000 @@ -1,37 +1,129 @@ #include "main.h" -DigitalIn bouton(p7); -int x,y,z,c; -bool release; -std::vector<int> x_array; -std::vector<int> y_array; -std::vector<int> z_array; +DigitalIn button(p7); +DigitalOut led(LED1); +int x,y,z,c, diff_x, diff_y,diff_z; +int x_array[2] = {0,0}; +int y_array[2] = {0,0}; +int z_array[2] = {0,0}; Serial pc(USBTX, USBRX); // PC serial communication +int find_min_max(int value,int array[]) +{ + + if(value<array[0]) + { + array[0] = value; + } + if(value>array[1]) + { + array[1] = value; + } + return true; +} + + +/* +void collector_init(void) +{ + + //CAPTURE + // Enable the pins on the device to use TIMER CAP2.0 on pin 30 + LPC_PINCON->PINSEL0 |= 3<<8; + + NVIC_SetVector(TIMER2_IRQn, uint32_t(TIMER2_IRQHandler)); + + // init Timer 2 (cap2.0 = DIP30, cap2.1 = DIP29) + LPC_SC->PCONP |= (1 << 22); // Timer2 power on + //LPC_SC->PCLKSEL1 |= (1 << 12); // Divide CCLK by 1 for Timer2 + LPC_TIM2->TC = 0; // clear timer counter + LPC_TIM2->PC = 0; // clear prescale counter + LPC_TIM2->PR = 0; // clear prescale register + LPC_TIM2->TCR = (1 << 1); // reset timer + LPC_TIM2->IR |= 1 << 0; // Clear MR0 interrupt flag + LPC_TIM2->CCR |= (7 << 0); // enable cap2.0 rising-edge capture and falling-edge; interrupt on cap2.0 + //LPC_TIM2->TCR = 1; // start Timer2 + + NVIC_EnableIRQ(TIMER2_IRQn); //enable timer2 interrupt + + // MATCH + // Enable the pins on the device to use TIMER MAT3.0 + LPC_PINCON->PINSEL0 |= 3<<20; + + NVIC_SetVector(TIMER3_IRQn, uint32_t(TIMER3_IRQHandler)); + + LPC_SC->PCONP |=1<<23; //timer3 power on + LPC_TIM3->MR0 = TIME; //100 msec ?? + LPC_TIM3->MCR |= 3; //interrupt and reset control + //3 = Interrupt & reset timer3 on match + //1 = Interrupt only, no reset of timer3 + LPC_TIM3->TC = 0; // clear timer counter + LPC_TIM3->PC = 0; // clear prescale counter + LPC_TIM3->PR = 0; // clear prescale register + LPC_TIM3->TCR = 0; //disable timer3 + LPC_TIM3->IR |= 1 << 0; // Clear MR0 interrupt flag + + + + NVIC_EnableIRQ(TIMER3_IRQn); //enable timer3 interrupt + + +} +extern "C" void TIMER2_IRQHandler (void) +{ + LPC_TIM3->TCR = 0; + + LPC_TIM2->IR |= 1 << 0; +} + +extern "C" void TIMER3_IRQHandler (void) +{ + x = getAccelValue(OUT_X_MSB); + y = getAccelValue(OUT_Y_MSB); + z = getAccelValue(OUT_Z_MSB); + + LPC_TIM3->IR |= 1 << 0; +}*/ void collector_thread(void const *args) { - while(1) + //collector_init(); + while(1) + { + if (button) { - if(bouton) - { + x = getAccelValue(OUT_X_MSB); + y = getAccelValue(OUT_Y_MSB); + z = getAccelValue(OUT_Z_MSB); - release = true; - x_array[c] = getAccelValue(OUT_X_MSB); - y_array[c]= getAccelValue(OUT_Y_MSB); - z_array[c]= getAccelValue(OUT_Z_MSB); - c++; + + find_min_max(z,z_array); + // pc.printf("\n\rz0: %d, z1: %d",z_array[0], z_array[1]); + // diff_x = abs(x_array[1] - x_array[0]); + // diff_y = abs(y_array[1] - y_array[0]); + diff_z = abs(z_array[1] - z_array[0]); + pc.printf("\n\r diff_z: %d", diff_z); + /* if(diff_x>35) + { + pc.printf("\n\r\n X MOVE \n"); } - else{ - if(release == true) - { - - pc.printf("bouton release"); - - pc.printf("d% ", x_array[0]); - release = false; - c = 0; - } - } - } + + if(diff_y>35) + { + pc.printf("\n\r\n Y MOVE\n"); + } + */ + if(diff_z>35 && diff_z<70) + { + pc.printf("\n\r\n Z MOVE\n"); + } + + + + + + // pc.printf("\n\rX: %d, Y: %d, Z: %d",x,y,z); + } + + } }
--- a/main.cpp Thu Mar 20 13:16:01 2014 +0000 +++ b/main.cpp Sun Mar 23 20:40:24 2014 +0000 @@ -1,5 +1,5 @@ #include "main.h" - + DigitalOut cs(p14); // Digital output used for the ship select control. DigitalOut myled(LED1); //LED SPI spi(p11, p12, p13); // SPI port (mosi, miso, sclk) @@ -77,25 +77,22 @@ return i2c_read_reg(MSB_addr); // Read MSB data from MSB register } - + int main() { - std::vector<int> x_array; -// int i = 0; + Thread thread1(collector_thread); //appelle des fonctions d'initialisations initAccel(); //accelerometre - - - myled = 0; + while(1) { - wait_ms(10); + }