RT-AICHIP-sample
mode_selectDuty.c
[詳解]
1 /* ------------------------------------------------------------ *
2 File mode_selectDuty.c
3 
4 duty maxで走らせるモード
5 
6 操作:
7  右SW: モータのdutyを変更
8  左SW: 長押しでモード選択へ繊維
9 
10 * ------------------------------------------------------------ */
11 #include "mode_selectDuty.h"
12 #include "type.h"
13 #include "AICHIPFunction.h"
14 #include "UserInterface.h"
15 #include "SystemTickTimer.h"
16 #include "debug.h"
17 
18 
19 void mode_selectDuty(void)
20 {
21  int8_t motor_duty = 0; //duty 0から100%まで1%刻み
22  int8_t sign = 1;
23 
24  myPrintfUART("############ duty select mode ################\n");
25  myPrintfUART("++++++++++++++++++++++++++++++++\n");
26  myPrintfUART(" Right SW: change motor duty .\n");
27  myPrintfUART(" Left SW: mode select .\n");
28  myPrintfUART("++++++++++++++++++++++++++++++++\n");
29 
30  while(1)
31  {
32  if(getRightSWcount() > 1000 ) wait1msec(100);
33  else wait1msec(1);
34 
35  //右SWでモータの状態を切り替え
36  if( getRightSWcount() >0)
37  {
38  motor_duty ++;
39  if(motor_duty == 101) sign *= -1;
40  motor_duty = motor_duty %101;
41 
42  myPrintfUART("\t motor duty: %d % \n",motor_duty);
43  //モーターのdutyを変える
44  setDutyMotor( (float)(sign * motor_duty)*0.01);
45  flashGreenLED(motor_duty,100 - motor_duty);
46 
47  while(getRightSWcount() != 0 ){
48  if(getRightSWcount() > 500)break;
49  };
50  }
51 
52  //モード選択へ遷移
53  if( getLeftSWcount() == 1000)
54  {
55  setDutyMotor(0.0);
56  turnGreenLED(0);
57  myPrintfUART("\t return mode select \n");
58  break;
59  }
60  }
61 }
62 
63 /******************************************************************************
64 ** End Of File
65 ******************************************************************************/
signed char int8_t
Definition: type.h:21
int myPrintfUART(const char *fmt,...)
Definition: debug.c:42
void setDutyMotor(float pwm_duty)
uint16_t getRightSWcount(void)
void flashGreenLED(uint16_t on_count, uint16_t off_count)
uint16_t getLeftSWcount(void)
Definition: UserInterface.c:98
void mode_selectDuty(void)
void wait1msec(uint32_t wait_count)
void turnGreenLED(uint8_t state)