![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
LPC824
Fork of CubeFine by
Diff: main.cpp
- Revision:
- 2:7964622fb5a5
- Parent:
- 1:54a2d380f8c7
--- a/main.cpp Fri Jul 01 09:41:15 2016 +0000 +++ b/main.cpp Mon Jul 04 07:17:39 2016 +0000 @@ -1,15 +1,13 @@ #include "mbed.h" -//#include "rtos.h" #include "MicroduinoPinNames.h" #include "userDef.h" #include "Protocol.h" #include "Microduino_Motor.h" -DigitalOut led_red(D5); Timer g_cubeTimer; //Timeout g_cubeTimeout; -#if 1 + Motor MotorLeft(motor_pin0A, motor_pin0B); Motor MotorRight(motor_pin1A, motor_pin1B); /////////////////////////////////////////////////////////// @@ -19,43 +17,22 @@ int16_t throttle = 0; //油门 int16_t steering = 0; //转向 int safe_ms = 0; -DigitalOut myled(D13); -InterruptIn wkp(D0); -InterruptIn wkp1(D1); + static long map(long x, long in_min, long in_max, long out_min, long out_max) { return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; } -/* -static void wake_up(void) -{ - //myled = 0; -} -*/ - int main() { -#if 0// To test wake up from deepsleep(), failed....but wake up from sleep() work. sleep() will reduce 2mA. - wkp.fall(wake_up); - wkp.rise(&wake_up); - wkp1.fall(&wake_up); - wkp1.rise(&wake_up); -#endif - led_red = 0; - //myled = 1; - //g_cubeTimer.start(); + + g_cubeTimer.start(); mode = protocolSetup(); //遥控接收器初始化 MotorLeft.Fix(motor_fixL); MotorRight.Fix(motor_fixR); - - MotorLeft.Driver(255); - MotorRight.Driver(255); - - wait(0.5); - //mypc.baud(115200); + while (1) { @@ -75,36 +52,7 @@ if (g_cubeTimer.read_ms() - safe_ms > SAFE_TIME_OUT) { MotorLeft.Free(); MotorRight.Free(); - //sleep();//待机待机电流可减少4mA左右 - //deepsleep(); } } // while -} - -#else -DigitalOut myled(D13); -PwmOut PWM_A(motor_pin0A); -PwmOut PWM_B(motor_pin0B); -int pv = 0; -int main() -{ - myled.write(1); - PWM_A.period_us(255); - PWM_B.period_us(255); - - PWM_A.pulsewidth_us(200); - PWM_B.pulsewidth_us(0); - while (1) { -#if 0 - PWM_B.pulsewidth_us(pv); - pv++; -#endif - wait(0.5); - myled = !myled; - if (pv >= 255) { - pv = 0; - } - } -} -#endif \ No newline at end of file +} \ No newline at end of file