質問編集履歴

1

2021/06/21 08:50

投稿

_nb_eri_
_nb_eri_

スコア4

test CHANGED
File without changes
test CHANGED
@@ -26,15 +26,73 @@
26
26
 
27
27
  ```C++(Arduino)
28
28
 
29
- #define M5STACK_MPU6886
30
-
31
-
32
-
33
29
  #include <M5Stack.h>
34
30
 
35
31
 
36
32
 
37
- /*変数定義略*/
33
+ const int pin_F = 19;
34
+
35
+ const int pin_R = 18;
36
+
37
+
38
+
39
+ const int PWM_CH_F = 1;
40
+
41
+ const int PWM_CH_R = 2;
42
+
43
+ const int PWM_Hz = 50;
44
+
45
+ const uint8_t PWM_level = 12;
46
+
47
+ //PWM resolution max1023?
48
+
49
+
50
+
51
+ const int Uprate = 1;
52
+
53
+ const int Deforate = pow(2, PWM_level) / 20;
54
+
55
+
56
+
57
+ signed int UDcount = 0;
58
+
59
+ char _data;
60
+
61
+
62
+
63
+ void startin(){
64
+
65
+ Serial.print("boot\r\n");
66
+
67
+ ledcWrite(PWM_CH_F, 0);
68
+
69
+ ledcWrite(PWM_CH_R, 0);
70
+
71
+ M5.Lcd.fillScreen(BLACK);
72
+
73
+ delay(500);
74
+
75
+
76
+
77
+ Serial.print("start\r\n");
78
+
79
+ ledcWrite(PWM_CH_F, 230);
80
+
81
+ ledcWrite(PWM_CH_R, 230);//1dato over current
82
+
83
+ delay(1000);
84
+
85
+
86
+
87
+ M5.Lcd.fillScreen(BLUE);
88
+
89
+
90
+
91
+ ledcWrite(PWM_CH_F, Deforate);
92
+
93
+ ledcWrite(PWM_CH_R, Deforate);
94
+
95
+ }
38
96
 
39
97
 
40
98
 
@@ -46,61 +104,35 @@
46
104
 
47
105
 
48
106
 
49
- M5.IMU.Init();
107
+ M5.Lcd.fillScreen(BLACK);
108
+
50
-
109
+ M5.Lcd.setTextColor(WHITE , BLACK);
51
-
52
110
 
53
111
  M5.Lcd.setTextSize(2);
54
112
 
55
- M5.Lcd.setTextColor(GREEN , BLACK);
113
+
56
-
114
+
57
- M5.Lcd.fillScreen(BLACK);
115
+ pinMode(pin_F, OUTPUT);
116
+
117
+ pinMode(pin_R, OUTPUT);
118
+
119
+
120
+
121
+ ledcSetup(PWM_CH_F, PWM_Hz, PWM_level);
122
+
123
+ ledcSetup(PWM_CH_R, PWM_Hz, PWM_level);
58
124
 
59
125
 
60
126
 
61
- m5.Lcd.setCursor(100, 100);
127
+ ledcAttachPin(pin_F, PWM_CH_F);
62
-
128
+
63
- m5.Lcd.printf("M5 boot\r\n");
129
+ ledcAttachPin(pin_R, PWM_CH_R);
64
130
 
65
131
 
66
132
 
67
- //まる1
133
+ startin();
68
-
69
-
70
-
71
- ledcSetup(PWM_CH_F, PWM_Hz, PWM_level);
134
+
72
-
73
- ledcSetup(PWM_CH_R, PWM_Hz, PWM_level);
74
-
75
-
76
-
77
- //まる2
78
-
79
-
80
-
81
- ledcAttachPin(pin_F, PWM_CH_F);// これと
82
-
83
- ledcAttachPin(pin_R, PWM_CH_R);// これのどっちかを消すとできる
84
-
85
-
86
-
87
- pinMode(pin_F, OUTPUT);
88
-
89
- pinMode(pin_R, OUTPUT);
90
-
91
-
92
-
93
- m5.Lcd.clear(WHITE);//まる1やまる2に移動させるとできる
94
-
95
- M5.Lcd.setTextColor(GREEN , WHITE);
96
-
97
-
98
-
99
- startin();//setupが長くなるので色々詰め込んだやつ
100
-
101
-
102
-
103
- m5.Lcd.printf("startin\r\n");//表示されない
135
+ m5.Lcd.printf("startin");
104
136
 
105
137
  }
106
138
 
@@ -108,28 +140,60 @@
108
140
 
109
141
  void loop() {
110
142
 
143
+ if(Serial.available() > 0){
144
+
145
+ _data = Serial.read();
146
+
147
+ Serial.printf("%c\r\n", _data);
148
+
149
+ }
150
+
151
+
152
+
111
- /*角度受け取る略*/
153
+ if(_data == 'w'){
154
+
112
-
155
+ UDcount ++;
156
+
113
-
157
+ ledcWrite(PWM_CH_F, Deforate + Uprate * UDcount);
158
+
114
-
159
+ ledcWrite(PWM_CH_R, Deforate + Uprate * UDcount);
160
+
161
+ Serial.printf("w %d\r\n", Deforate + Uprate * UDcount);
162
+
163
+ }
164
+
165
+ else if(_data == 's'){
166
+
167
+ UDcount --;
168
+
169
+ ledcWrite(PWM_CH_F, Deforate + Uprate * UDcount);
170
+
171
+ ledcWrite(PWM_CH_R, Deforate + Uprate * UDcount);
172
+
173
+ Serial.printf("s %d\r\n", Deforate + Uprate * UDcount);
174
+
175
+ }
176
+
177
+ else if(_data == 'r'){
178
+
179
+ UDcount = 0;
180
+
181
+ startin();
182
+
183
+ }
184
+
185
+ else if(_data == 'e'){
186
+
115
- M5.Lcd.setCursor(0, 100);
187
+ ledcWrite(PWM_CH_F, 0);
116
-
117
- delta_pitch = (my_pitch - default_pitch) * DTR;
188
+
118
-
119
- delta_roll = (my_roll - default_roll) * DTR;
120
-
121
- M5.Lcd.printf("dP = %5.1f, dR = %5.1f", delta_pitch, delta_roll);//表示されない
122
-
123
-
124
-
125
- /*Lcdの操作はないので省略*/
189
+ ledcWrite(PWM_CH_R, 0);
190
+
191
+ }
126
192
 
127
193
  }
128
194
 
129
195
 
130
196
 
131
-
132
-
133
197
  ```
134
198
 
135
199