Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "mcu_api.h"
- #include "mcu_errno.h"
- #define OUTPUT 1
- #define LED_GPIO 40
- #define ON 1
- #define OFF 0
- #define PWM0 0
- #define WAIT_INTERVAL 100
- #define PWM_DUTY_LEFT_NS 1000000
- #define PWM_DUTY_CENTER_NS 1500000
- #define PWM_DUTY_RIGHT_NS 2000000
- #define PWM_PERIOD_NS 20000000
- void mcu_main()
- {
- /* your configuration code starts here */
- char buf[64];
- int len = 0;
- gpio_setup(LED_GPIO, OUTPUT);
- pwm_disable(PWM0);
- while (1) /* your loop code starts here */
- {
- len = host_receive((unsigned char*) buf, 64);
- if (len >0) {
- debug_print(DBG_INFO, "received command!\n");
- int duty_ns = PWM_DUTY_CENTER_NS;
- if (strncmp(buf, "left", 4) == 0) {
- duty_ns = PWM_DUTY_LEFT_NS;
- debug_print(DBG_INFO, "Left\n");
- }
- else if (strncmp(buf, "right", 5) == 0) {
- duty_ns = PWM_DUTY_RIGHT_NS;
- debug_print(DBG_INFO, "Right\n");
- }
- else {
- debug_print(DBG_INFO, "Center\n");
- }
- pwm_configure(PWM0, duty_ns, PWM_PERIOD_NS);
- pwm_enable(PWM0);
- }
- gpio_write(LED_GPIO, ON);
- mcu_sleep(WAIT_INTERVAL);
- gpio_write(LED_GPIO, OFF);
- mcu_sleep(WAIT_INTERVAL);
- }
- }
Add Comment
Please, Sign In to add comment