2
2
3
3
n = Neosoco ()
4
4
5
+ ## LED
5
6
# case1) Turn on LED with 100% brightness during 1s
6
7
# n.led_on('out1', '100')
7
8
# wait(1000)
10
11
# n.set_value('out1', 255)
11
12
# wait(1000)
12
13
14
+ ## LED, distance sensor
13
15
# case3) Turn on LED when the distance is under 10cm
14
16
# while True:
15
17
# if n.get_value('in1') < 10:
16
18
# n.led_on('out1', '100')
17
19
# else:
18
20
# n.led_off('out1')
19
21
22
+ ## Motors
20
23
# case4-1) Move forth and back during 1s and stop
21
24
# n.motor_move('forward')
22
25
# wait(500)
40
43
# n.motor_move('stop')
41
44
42
45
# case5) Move forth and back with speed 30% during 1s and stop
43
- n .motor_rotate ('both' , 'forward' , '30' )
44
- wait (500 )
45
- n .motor_rotate ('both' , 'backward' , '30' )
46
- wait (500 )
47
- n .motor_move ('stop' )
46
+ # n.motor_rotate('both', 'forward', '30')
47
+ # wait(500)
48
+ # n.motor_rotate('both', 'backward', '30')
49
+ # wait(500)
50
+ # n.motor_move('stop')
48
51
52
+ ## Buzzer
49
53
# case6) Play same note by pitch, sharp and flat, and a length of note
50
54
# n.buzzer('3', n.NOTE_NAME_C)
51
55
# n.buzzer('3', 'c')
60
64
# while True:
61
65
# n.buzzer_by_port('in1')
62
66
67
+ ## Color LED, distance sensor
63
68
# case8) Color LED on with variable color by input port
64
69
# r = g = b = n.convert_scale('in1', 0, 255, 85, 170) # Limit to middle brightness
65
- # color_led_on('out1', r, g, b)
70
+ # color_led_on('out1', r, g, b)
71
+
72
+ ## LED, Angle sensor
73
+ # case9) # Turn on LED when a degree of the angle sensor is under 90 degrees
74
+ while True :
75
+ if n .get_angle ('in1' ) < 90 :
76
+ n .led_on ('out1' , '100' )
77
+ else :
78
+ n .led_off ('out1' )
0 commit comments