示例#1
0
void APP_Run(void) {
  uint8_t res=ERR_OK;
  uint8_t xyz[3];
  
  LED1_On();
  LED2_On();
  LED3_On();
  res = MMA8451_Init();
  while (res==ERR_OK) {
    res = MMA8451_GetRawXYZ(&xyz[0]);
    LED1_Put(xyz[0]>50);
    LED2_Put(xyz[1]>50);
    LED3_Put(xyz[2]>50);
  }
  LED1_Off();
  LED2_Off();
  LED3_Off();
}
示例#2
0
void accelTest(void){
	uint8_t res = ERR_OK;
	int8_t dataX = 0;

	deviceData.handle = I2C1_Init(&deviceData);

#if 0
	uint8_t data = 0;
	int8_t i = 2;




	WAIT1_WaitCycles(25);
	res = LIS2DH12TR_ReadReg(0x0f, &data, sizeof(data));
	WAIT1_WaitCycles(25);
	res = LIS2DH12TR_WriteReg(0x20, 0b01111111);
	WAIT1_WaitCycles(25);
	res = LIS2DH12TR_WriteReg(0x23, 0b00100000);

	for(;;){
		WAIT1_WaitCycles(25);
		res = LIS2DH12TR_ReadReg(0x29, &dataX, 1U);

		if(dataX > i){
			LED1_On();
			i = -1;
		} else if(dataX < i){
			LED1_Off();
			i = 1;
		}
	}
#else

#define MASK_LED1	0x04
#define MASK_LED2	0x02
#define MASK_LED3	0x01
#define PIXEL_TIME_MS	1

	uint8_t img[] = {7,2,7,0,7,7,7,0,7,4,4,0,7,4,7};

	WAIT1_WaitCycles(25);
	res = LIS2DH12TR_WriteReg(0x20, 0b01111111);
	WAIT1_WaitCycles(25);
	res = LIS2DH12TR_WriteReg(0x23, 0b00100000);
	WAIT1_WaitCycles(25);

	bool swipeRight = FALSE;
	bool swipeLeft = FALSE;

	uint8_t right = 0;
	uint8_t left = 0;

	uint8_t prevAccelValue = 0;
	uint8_t lengthOfImage = sizeof(img);

	while(1){
		//WAIT1_WaitCycles(25);
		WAIT1_Waitms(1);
		res = LIS2DH12TR_ReadReg(0x29, &dataX, 1U);

		if(dataX < prevAccelValue){
			right++;
			if(right == 3){
				swipeRight = TRUE;
				right = 0;
			}
		} /*else if(dataX > prevAccelValue){
			left++;
			if(left == 3){
				swipeLeft = TRUE;
				left = 0;
			}
		}*/
		prevAccelValue = dataX;

		if ((dataX > 40) & swipeRight){

			WAIT1_Waitms(10);

			for(int i=0; i<lengthOfImage; i++){
				LED1_Put(img[i] & MASK_LED1);
				LED2_Put(img[i] & MASK_LED2);
				LED3_Put(img[i] & MASK_LED3);

				WAIT1_Waitms(PIXEL_TIME_MS);

				LED1_Off();
				LED2_Off();
				LED3_Off();

				WAIT1_Waitms(PIXEL_TIME_MS);
			}
			swipeRight = FALSE;
		} /*else if ((dataX < 40) & swipeLeft){

			WAIT1_Waitms(10);

			for(int i=(lengthOfImage-1); i>=0; i--){
				LED1_Put(img[i] & MASK_LED1);
				LED2_Put(img[i] & MASK_LED2);
				LED3_Put(img[i] & MASK_LED3);

				WAIT1_Waitms(PIXEL_TIME_MS);

				LED1_Off();
				LED2_Off();
				LED3_Off();

				WAIT1_Waitms(PIXEL_TIME_MS);
			}
			swipeLeft = FALSE;
		}*/
		//prevAccelValue = 0;
	}
#endif
}