質問編集履歴
1
fourteenlength様からご指摘いただいたソースコードについて再度編集しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -38,7 +38,7 @@
|
|
38
38
|
|
39
39
|
|
40
40
|
|
41
|
-
|
41
|
+
```python
|
42
42
|
|
43
43
|
import RPi.GPIO as GPIO
|
44
44
|
|
@@ -57,6 +57,8 @@
|
|
57
57
|
SV_DUTY_RES = (2.4 - 0.5) / 20 / 180
|
58
58
|
|
59
59
|
SENSOR_PORT = 27
|
60
|
+
|
61
|
+
|
60
62
|
|
61
63
|
# GPIOの設定 --- (*2)
|
62
64
|
|
@@ -80,15 +82,15 @@
|
|
80
82
|
|
81
83
|
def set_angle(angle):
|
82
84
|
|
83
|
-
degree = angle + 90
|
85
|
+
degree = angle + 90
|
84
86
|
|
85
|
-
duty = (SV_DUTY_OFFSET + SV_DUTY_RES * degree) * 100
|
87
|
+
duty = (SV_DUTY_OFFSET + SV_DUTY_RES * degree) * 100
|
86
88
|
|
87
|
-
print("angle=",angle,"duty=", int(duty))
|
89
|
+
print("angle=",angle,"duty=", int(duty))
|
88
90
|
|
89
|
-
servo.ChangeFrequency(SV_FREQ)
|
91
|
+
servo.ChangeFrequency(SV_FREQ)
|
90
92
|
|
91
|
-
servo.ChangeDutyCycle(duty)
|
93
|
+
servo.ChangeDutyCycle(duty)
|
92
94
|
|
93
95
|
|
94
96
|
|
@@ -96,33 +98,35 @@
|
|
96
98
|
|
97
99
|
while True:
|
98
100
|
|
99
|
-
v = GPIO.input(SENSOR_PORT)
|
101
|
+
v = GPIO.input(SENSOR_PORT)
|
100
102
|
|
101
|
-
if v == GPIO.HIGH:
|
103
|
+
if v == GPIO.HIGH:
|
102
104
|
|
103
|
-
GPIO.output(SV_PORT, GPIO.HIGH)
|
105
|
+
GPIO.output(SV_PORT, GPIO.HIGH)
|
104
106
|
|
105
|
-
try:
|
107
|
+
try:
|
106
108
|
|
107
|
-
set_angle(90)
|
109
|
+
set_angle(90)
|
108
110
|
|
109
|
-
sleep(1)
|
111
|
+
sleep(1)
|
110
112
|
|
111
113
|
|
112
114
|
|
113
|
-
set_angle(-90)
|
115
|
+
set_angle(-90)
|
114
116
|
|
115
|
-
sleep(1)
|
117
|
+
sleep(1)
|
116
118
|
|
119
|
+
except KeyboardInterrupt:
|
117
120
|
|
118
|
-
|
119
|
-
except KeyboardInterrupt:
|
120
|
-
|
121
|
-
break
|
121
|
+
break
|
122
122
|
|
123
123
|
|
124
124
|
|
125
125
|
GPIO.cleanup()
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
```
|
126
130
|
|
127
131
|
|
128
132
|
|