Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ***********************************************************
- // test2.c
- //
- // ***********************************************************
- #include "test.h"
- #include "../drivers.h"
- #include "../bsp.h"
- #define PWM_LEFT TIM4_CH1
- #define PWM_TOP TIM4_CH2
- #define PWM_RIGHT TIM4_CH3
- #define PWM_BOTTOM TIM4_CH4
- static uint16_t Interpolate(int8_t Value)
- {
- uint32_t Abs = (Value > 0) ? Value : -Value;
- return Abs * 0xFFFF / 128;
- }
- static void test2_onTimer(void)
- {
- int8_t X = acc_GetX();
- int8_t Y = acc_GetY();
- if(Y > 0)
- {
- pwm_Set(PWM_LEFT, Interpolate(Y));
- pwm_Set(PWM_RIGHT, 0);
- }
- else
- {
- pwm_Set(PWM_LEFT, 0);
- pwm_Set(PWM_RIGHT, Interpolate(Y));
- }
- if(X > 0)
- {
- pwm_Set(PWM_TOP, Interpolate(X));
- pwm_Set(PWM_BOTTOM, 0);
- }
- else
- {
- pwm_Set(PWM_TOP, 0);
- pwm_Set(PWM_BOTTOM, Interpolate(X));
- }
- }
- void test2_Init(void)
- {
- // Перехватим светодиоды у модуля led.с:
- pwm_Init(PWM_LEFT);
- pwm_Init(PWM_TOP);
- pwm_Init(PWM_RIGHT);
- pwm_Init(PWM_BOTTOM);
- timer_AddFunction(50, &test2_onTimer);
- }
- void test2_Main(void)
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement