Facebook
From pussyhounter69, 6 Years ago, written in C.
Embed
Download Paste or View Raw
Hits: 288
  1. /**
  2.   ******************************************************************************
  3.   * @file    main.c
  4.   * @author  Ac6
  5.   * @version V1.0
  6.   * @date    01-December-2013
  7.   * @brief   Default main function.
  8.   ******************************************************************************
  9. */
  10.  
  11.  
  12. #include "stm32f4xx.h"
  13. #include "stm32f4_discovery.h"
  14. #include "tm_stm32f4_lis302dl_lis3dsh.h"
  15.  
  16. TM_LIS302DL_LIS3DSH_t Axes_Data;
  17. double x,y,z;
  18. double sumakwadratow;
  19.  
  20. int main(void)
  21. {
  22.         RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
  23.  
  24.             GPIO_InitTypeDef  GPIO_InitStructure;
  25.             /* Configure PD12, PD13, PD14 and PD15 in output pushpull mode */
  26.             GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14| GPIO_Pin_15;
  27.             GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  28.             GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  29.             GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  30.             GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  31.             GPIO_Init(GPIOD, &GPIO_InitStructure);
  32.  
  33.             unsigned int i;
  34.  
  35.  
  36.  
  37.  
  38.  
  39.         typedef enum {
  40.             TM_LIS302DL_LIS3DSH_Device_Error,
  41.             TM_LIS302DL_LIS3DSH_Device_LIS302DL,
  42.             TM_LIS302DL_LIS3DSH_Device_LIS3DSH
  43.         } TM_LIS302DL_LIS3DSH_Device_t;
  44.  
  45.  
  46.         typedef struct {
  47.             int16_t X;
  48.             int16_t Y;
  49.             int16_t Z;
  50.         } TM_LIS302DL_LIS3DSH_t;
  51.  
  52.         TM_LIS302DL_LIS3DSH_Init(TM_LIS302DL_Sensitivity_2_3G, TM_LIS302DL_Filter_2Hz);
  53.  
  54.         TM_LIS302DL_LIS3DSH_Device_t IMU_Type;
  55.         IMU_Type = TM_LIS302DL_LIS3DSH_Detect();
  56.  
  57.  
  58.  
  59.         for(;;)
  60.         {
  61.                 TM_LIS302DL_LIS3DSH_ReadAxes(&Axes_Data);
  62.                 x=(double)Axes_Data.X*0.01796875;
  63.                 y=(double)Axes_Data.Y*0.01796875;
  64.                 z=(double)Axes_Data.Z*0.01796875;
  65.  
  66.                 sumakwadratow = x*x + y*y + z*z;
  67.  
  68.                 if(sumakwadratow>=1)
  69.                 {
  70.                         GPIO_SetBits(GPIOD, GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);
  71.                 }
  72.                 else
  73.                 {
  74.                         GPIO_ResetBits(GPIOD, GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);
  75.  
  76.                 }
  77.  
  78.  
  79.  
  80.  
  81.         }
  82. }
  83.