Current SVN has x and y inverted and one of the axes responding in the opposite manner to the other one.
The following code make tipping the board left and right light up the left-most and right-most LEDs. It changes the reaction to be consistent on both pairs: highest side of the board lights up.
Code: Select all
/* Calculating average of the latest four accelerometer readings.*/
y = ((int32_t)xbuf[0] + (int32_t)xbuf[1] +
(int32_t)xbuf[2] + (int32_t)xbuf[3]) / 4;
x = ((int32_t)ybuf[0] + (int32_t)ybuf[1] +
(int32_t)ybuf[2] + (int32_t)ybuf[3]) / 4;
/* Reprogramming the four PWM channels using the accelerometer data.*/
if (y < 0) {
pwmEnableChannel(&PWMD4, 2, (pwmcnt_t)-y);
pwmEnableChannel(&PWMD4, 0, (pwmcnt_t)0);
}
else {
pwmEnableChannel(&PWMD4, 0, (pwmcnt_t)y);
pwmEnableChannel(&PWMD4, 2, (pwmcnt_t)0);
}
if (x < 0) {
pwmEnableChannel(&PWMD4, 1, (pwmcnt_t)-x);
pwmEnableChannel(&PWMD4, 3, (pwmcnt_t)0);
}
else {
pwmEnableChannel(&PWMD4, 3, (pwmcnt_t)x);
pwmEnableChannel(&PWMD4, 1, (pwmcnt_t)0);
}
OK , it's only a demo and it does demonstrate the RTOS functionality but it seems like it was written by someone who did not have access to the hardware. It would look a bit sharper if the LEDs came on in a logical way.