Example #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();
}
Example #2
0
static portTASK_FUNCTION(MainTask, pvParameters) {
#if PL_HAS_ACCELEROMETER
  int16_t xmg, ymg;
#endif

  (void)pvParameters; /* parameter not used */
#if PL_HAS_MINI_INI
  TestMiniIni();
#endif
  for(;;) {
#if PL_HAS_ACCELEROMETER
    xmg = FX1_GetXmg();
    ymg = FX1_GetYmg();
    LED1_Put(xmg>100||xmg<-100||ymg>100||ymg<-100);
    LED2_Put(xmg>500||xmg<-500||ymg>500||ymg<-500);
#endif
    LED3_Neg();
#if PL_HAS_KEYS
    KEY1_ScanKeys();
#endif
    FRTOS1_vTaskDelay(100/portTICK_RATE_MS);
  }
}
Example #3
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
}