smalruby 0.1.0-x86-mingw32 → 0.1.1-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of smalruby might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3bdbbd5b69c734772bc38fe43b03e93c3f5ef9ff
4
- data.tar.gz: 144736a1788627f04fde909e67f97562a1a76f89
3
+ metadata.gz: b5c901b60e685ae7c19761cd508dfe594ee3b85f
4
+ data.tar.gz: 97525fa3c33e1bc7a1f8683932580cabf9273b0e
5
5
  SHA512:
6
- metadata.gz: 744f9edee798445e6f036eb19da4e961599640c2fc840c38162b2450b79e7ab14d576f0837295f20119369f6a121a82e35cd6d99a088a1e055f7a6ab43c5f29a
7
- data.tar.gz: 311f521c3a1cf9607a8014e525c763bff43c770d391661d117f48408bb36d368030f6c3f09b47635d983eca54962dd935252e38c16fd1c23fbc01982f8600423
6
+ metadata.gz: 09aea517a57d82aa6e45d120fe2174b8181af703980ad1961bcef5d850b1a957e5a7f5d3045ba38444a2f42ae0919569b9b9b60a0a453ab1aa913d5f82c21441
7
+ data.tar.gz: fd3a9e698fbdd31b225bd0340577c4dbdcb01f5bc9e8a12320bf43a95c5f2a49acbfa61347b6d75476ef426db0fe63cf6c7259e4dcf139cbf09168d503130015
data/lib/smalruby.rb CHANGED
@@ -143,10 +143,6 @@ module Smalruby
143
143
 
144
144
  hit
145
145
 
146
- sensor_change
147
-
148
- button_change
149
-
150
146
  world.objects.delete_if do |o|
151
147
  o.join unless o.alive?
152
148
  o.vanished?
@@ -219,46 +215,6 @@ module Smalruby
219
215
  end
220
216
  end
221
217
  end
222
-
223
- def sensor_change
224
- if world.sensor_change_queue.length > 0
225
- sensor_change_queue = nil
226
- world.sensor_change_queue.synchronize do
227
- sensor_change_queue = world.sensor_change_queue.dup
228
- world.sensor_change_queue.clear
229
- end
230
-
231
- world.objects.each do |o|
232
- if o.respond_to?(:sensor_change)
233
- sensor_change_queue.each do |pin, value|
234
- o.sensor_change(pin, value)
235
- end
236
- end
237
- end
238
- end
239
- end
240
-
241
- def button_change
242
- if world.button_change_queue.length > 0
243
- queue = nil
244
- world.button_change_queue.synchronize do
245
- queue = world.button_change_queue.dup
246
- world.button_change_queue.clear
247
- end
248
-
249
- world.objects.each do |o|
250
- if o.respond_to?(:button_up) && o.respond_to?(:button_down)
251
- queue.each do |pin, up_or_down|
252
- if up_or_down == :up
253
- o.button_up(pin)
254
- else
255
- o.button_down(pin)
256
- end
257
- end
258
- end
259
- end
260
- end
261
- end
262
218
  end
263
219
  end
264
220
 
@@ -406,6 +406,11 @@ module Smalruby
406
406
  Hardware.create_hardware(Hardware::Sensor, pin)
407
407
  end
408
408
 
409
+ # create or get Hardware::SmalrubotV3 instance
410
+ def smalrubot_v3
411
+ Hardware.create_hardware(Hardware::SmalrubotV3)
412
+ end
413
+
409
414
  # @!endgroup
410
415
 
411
416
  def draw
@@ -427,10 +432,6 @@ module Smalruby
427
432
  @checking_hit_targets << options
428
433
  @checking_hit_targets.flatten!
429
434
  @checking_hit_targets.uniq!
430
- when :sensor_change
431
- sensor(options.first)
432
- when :button_up, :button_down
433
- button(options.first)
434
435
  end
435
436
  end
436
437
 
@@ -480,27 +481,6 @@ module Smalruby
480
481
  end
481
482
  end
482
483
 
483
- def sensor_change(pin, value)
484
- @event_handlers[:sensor_change].try(:each) do |h|
485
- next unless h.options.include?(pin)
486
- @threads << h.call(value)
487
- end
488
- end
489
-
490
- def button_up(pin)
491
- @event_handlers[:button_up].try(:each) do |h|
492
- next unless h.options.include?(pin)
493
- @threads << h.call
494
- end
495
- end
496
-
497
- def button_down(pin)
498
- @event_handlers[:button_down].try(:each) do |h|
499
- next unless h.options.include?(pin)
500
- @threads << h.call
501
- end
502
- end
503
-
504
484
  def alive?
505
485
  @threads.compact!
506
486
  @threads.delete_if { |t|
@@ -20,6 +20,8 @@ module Smalruby
20
20
  autoload :Button
21
21
  autoload :Sensor
22
22
 
23
+ autoload :SmalrubotV3
24
+
23
25
  module_function
24
26
 
25
27
  # ハードウェアを準備する
@@ -68,7 +70,7 @@ module Smalruby
68
70
  # @param [Class] klass ハードウェアのクラス
69
71
  # @param [String|Numeric] pin ピン番号
70
72
  # @return [Object] ハードウェアのインスタンス
71
- def create_hardware(klass, pin)
73
+ def create_hardware(klass, pin = nil)
72
74
  klass = NullHardware unless @initialized_hardware
73
75
  key = [klass, pin]
74
76
  @hardware_cache.synchronize do
@@ -6,22 +6,29 @@ module Smalruby
6
6
  # ボタンを表現するクラス
7
7
  class Button < Smalrubot::Components::BaseComponent
8
8
  def initialize(options)
9
- @using_pullup = true
10
9
  super(board: world.board, pin: Pin.smalruby_to_smalrubot(options[:pin]),
11
- pullup: true)
10
+ pullup: false)
12
11
  end
13
12
 
14
- def up?
15
- digital_read(pin) == Smalrubot::Board::LOW
13
+ def released?
14
+ board.digital_read(pin) == 0
16
15
  end
17
16
 
18
- alias_method :off?, :up?
17
+ alias_method :off?, :released?
18
+ alias_method :up?, :released?
19
19
 
20
- def down?
21
- !up?
20
+ def pressed?
21
+ !released?
22
22
  end
23
23
 
24
- alias_method :on?, :down?
24
+ alias_method :on?, :pressed?
25
+ alias_method :down?, :pressed?
26
+
27
+ private
28
+
29
+ def after_initialize(_ = {})
30
+ set_pin_mode(:in)
31
+ end
25
32
  end
26
33
  end
27
34
  end
@@ -9,14 +9,16 @@ module Smalruby
9
9
  super(board: world.board, pin: Pin.smalruby_to_smalrubot(options[:pin]))
10
10
  end
11
11
 
12
- # @!method on
12
+ # @!method turn_on
13
13
  # LEDをオンにする
14
+ alias_method :turn_on, :on
14
15
 
15
- # @!method off
16
+ # @!method turn_off
16
17
  # LEDをオフにする
18
+ alias_method :turn_off, :off
17
19
 
18
20
  def stop
19
- off
21
+ turn_off
20
22
  end
21
23
  end
22
24
  end
@@ -17,14 +17,9 @@ module Smalruby
17
17
  end
18
18
  end
19
19
 
20
- # RGB LEDをオンにする
21
- def on(options = {})
22
- defaults = {
23
- color: 'white'
24
- }
25
- opts = Util.process_options(options, defaults)
26
-
27
- color = Color.smalruby_to_dxruby(opts[:color])
20
+ # RGB LEDを指定した色に光らせる
21
+ def color=(val)
22
+ color = Color.smalruby_to_dxruby(val)
28
23
  analog_write(pins[0], calc_value(color[0]))
29
24
  analog_write(pins[1], calc_value(color[1]))
30
25
  analog_write(pins[2], calc_value(color[2]))
@@ -32,19 +27,19 @@ module Smalruby
32
27
  end
33
28
 
34
29
  # RGB LEDをオフにする
35
- def off
30
+ def turn_off
36
31
  digital_write(pins[3], Smalrubot::Board::LOW)
37
32
  end
38
33
 
39
34
  def stop
40
- off
35
+ turn_off
41
36
  end
42
37
 
43
38
  private
44
39
 
45
40
  def after_initialize(_ = {})
46
41
  set_pin_mode(pins[3], :out)
47
- off
42
+ turn_off
48
43
  end
49
44
 
50
45
  def calc_value(value)
@@ -17,21 +17,16 @@ module Smalruby
17
17
  end
18
18
  end
19
19
 
20
- # RGB LEDをオンにする
21
- def on(options = {})
22
- defaults = {
23
- color: 'white'
24
- }
25
- opts = Util.process_options(options, defaults)
26
-
27
- color = Color.smalruby_to_dxruby(opts[:color])
20
+ # RGB LEDを指定した色に光らせる
21
+ def color=(val)
22
+ color = Color.smalruby_to_dxruby(val)
28
23
  analog_write(pins[0], calc_value(color[0]))
29
24
  analog_write(pins[1], calc_value(color[1]))
30
25
  analog_write(pins[2], calc_value(color[2]))
31
26
  end
32
27
 
33
28
  # RGB LEDをオフにする
34
- def off
29
+ def turn_off
35
30
  color = Color.smalruby_to_dxruby('black')
36
31
  analog_write(pins[0], calc_value(color[0]))
37
32
  analog_write(pins[1], calc_value(color[1]))
@@ -39,13 +34,13 @@ module Smalruby
39
34
  end
40
35
 
41
36
  def stop
42
- off
37
+ turn_off
43
38
  end
44
39
 
45
40
  private
46
41
 
47
42
  def after_initialize(_ = {})
48
- off
43
+ turn_off
49
44
  end
50
45
 
51
46
  def calc_value(value)
@@ -0,0 +1,143 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'smalruby/hardware'
3
+
4
+ module Smalruby
5
+ module Hardware
6
+ # Smalrubot v3 class
7
+ class SmalrubotV3
8
+ # wait time for next action
9
+ WAIT_TIME = 0.01
10
+
11
+ @mutex = Mutex.new
12
+
13
+ class << self
14
+ # lock for motor driver
15
+ def lock(&block)
16
+ @mutex.synchronize do
17
+ yield
18
+ end
19
+ end
20
+
21
+ # unlock for motor driver
22
+ def unlock(&block)
23
+ @mutex.unlock
24
+ yield
25
+ ensure
26
+ @mutex.lock
27
+ end
28
+ end
29
+
30
+ # Red LED that is connected D13
31
+ attr_reader :red_led
32
+
33
+ # Green LED that is connected D2
34
+ attr_reader :green_led
35
+
36
+ # Left Motor that is connected D6, D7, D8
37
+ attr_reader :left_motor
38
+
39
+ # Right Motor that is connected D9, D10, D11
40
+ attr_reader :right_motor
41
+
42
+ # Left touch sensor that is connected D4
43
+ attr_reader :left_touch_sensor
44
+
45
+ # Right touch sensor that is connected D3
46
+ attr_reader :right_touch_sensor
47
+
48
+ # Light sensor that is connected A0
49
+ attr_reader :light_sensor
50
+
51
+ def initialize(_)
52
+ @red_led = Led.new(pin: 'D13')
53
+ @green_led = Led.new(pin: 'D2')
54
+
55
+ @left_motor = MotorDriver.new(pin: 'D6')
56
+ @left_motor.speed = 100
57
+ @right_motor = MotorDriver.new(pin: 'D9')
58
+ @right_motor.speed = 100
59
+
60
+ @left_touch_sensor = Button.new(pin: 'D4')
61
+ @right_touch_sensor = Button.new(pin: 'D3')
62
+
63
+ @light_sensor = Sensor.new(pin: 'A0')
64
+
65
+ @current_motor_direction = :stop
66
+ end
67
+
68
+ # @!method forward(sec: nil)
69
+ # forward
70
+ #
71
+ # @param [Float] time of forwarding
72
+
73
+ # @!method backward(sec: nil)
74
+ # backward
75
+ #
76
+ # @param [Float] time of backwarding
77
+
78
+ # @!method turn_left(sec: nil)
79
+ # turn left
80
+ #
81
+ # @param [Float] time of turning left
82
+
83
+ # @!method turn_right(sec: nil)
84
+ # turn right
85
+ #
86
+ # @param [Float] time of turning right
87
+ %i(forward backward turn_left turn_right).each do |direction|
88
+ define_method(direction) do |sec: nil|
89
+ run(direction, sec: sec)
90
+ end
91
+ end
92
+
93
+ # stop
94
+ #
95
+ # @param [Float] time of stopping
96
+ def stop(sec: WAIT_TIME)
97
+ self.class.lock do
98
+ @left_motor.stop
99
+ @right_motor.stop
100
+ @current_motor_direction = :stop
101
+ if (sec = sec.to_f) > 0
102
+ sleep(sec)
103
+ end
104
+ end
105
+ end
106
+
107
+ private
108
+
109
+ def run(direction, sec: nil)
110
+ self.class.lock do
111
+ if @current_motor_direction != :stop
112
+ self.class.unlock do
113
+ stop(sec: WAIT_TIME)
114
+ end
115
+ end
116
+ case direction
117
+ when :forward
118
+ @left_motor.forward
119
+ @right_motor.forward
120
+ when :backward
121
+ @left_motor.backward
122
+ @right_motor.backward
123
+ when :turn_left
124
+ @left_motor.backward
125
+ @right_motor.forward
126
+ when :turn_right
127
+ @left_motor.forward
128
+ @right_motor.backward
129
+ end
130
+ @current_motor_direction = direction
131
+ if (sec = sec.to_f) > 0
132
+ sleep(sec)
133
+ if direction != :stop
134
+ self.class.unlock do
135
+ stop
136
+ end
137
+ end
138
+ end
139
+ end
140
+ end
141
+ end
142
+ end
143
+ end
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  module Smalruby
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
@@ -9,28 +9,10 @@ module Smalruby
9
9
  attr_accessor :objects
10
10
  attr_accessor :board
11
11
  attr_accessor :current_stage
12
- attr_reader :sensor_change_queue
13
- attr_reader :button_change_queue
14
12
 
15
13
  def initialize
16
14
  @objects = []
17
15
  @board = nil
18
- @sensor_change_queue = []
19
- @sensor_change_queue.extend(Mutex_m)
20
- @button_change_queue = []
21
- @button_change_queue.extend(Mutex_m)
22
- end
23
-
24
- def sensor_changed(pin, value)
25
- @sensor_change_queue.synchronize do
26
- @sensor_change_queue.push([pin, value])
27
- end
28
- end
29
-
30
- def button_changed(pin, up_or_down)
31
- @button_change_queue.synchronize do
32
- @button_change_queue.push([pin, up_or_down])
33
- end
34
16
  end
35
17
  end
36
18
  end
@@ -112,34 +112,5 @@ stage1.on(:start) do
112
112
  fill(color: 'white')
113
113
  draw_font(string: "右の速度: #{motor_driver('D9').speed}%", color: 'black')
114
114
  end
115
-
116
- if Input.key_down?(K_SPACE)
117
- fill(color: 'white')
118
- draw_font(string: '右のLED赤色を光らせる', color: 'black')
119
-
120
- led('D13').on
121
-
122
- await until !Input.key_down?(K_SPACE)
123
-
124
- led('D13').off
125
-
126
- fill(color: 'white')
127
- draw_font(string: '左のLED緑色を光らせる', color: 'black')
128
-
129
- led('D2').on
130
-
131
- sleep(1)
132
-
133
- led('D2').off
134
- end
135
-
136
- if Input.key_down?(K_B)
137
- until !Input.key_down?(K_B)
138
- fill(color: 'white')
139
- draw_font(string: "センサーの情報#{sensor('A0').value}", color: 'black')
140
- await
141
- end
142
- fill(color: 'white')
143
- end
144
115
  end
145
116
  end
@@ -0,0 +1,187 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ DESCRIPTION = <<EOS
4
+ スモウルボットV3を操作します
5
+ EOS
6
+
7
+ require 'smalruby'
8
+
9
+ init_hardware
10
+
11
+ Smalrubot.debug_mode = true
12
+
13
+ stage1 = Stage.new(color: 'white')
14
+ stage1.smalrubot_v3
15
+
16
+ stage1.on(:start) do
17
+ fill(color: 'white')
18
+ draw_font(string: DESCRIPTION, color: 'black')
19
+
20
+ loop do
21
+ if Input.key_down?(K_UP)
22
+ fill(color: 'white')
23
+ draw_font(string: '進む', color: 'black')
24
+
25
+ smalrubot_v3.forward
26
+
27
+ await until !Input.key_down?(K_UP)
28
+
29
+ fill(color: 'white')
30
+
31
+ smalrubot_v3.stop
32
+ end
33
+
34
+ if Input.key_down?(K_DOWN)
35
+ fill(color: 'white')
36
+ draw_font(string: 'バックする', color: 'black')
37
+
38
+ smalrubot_v3.backward
39
+
40
+ await until !Input.key_down?(K_DOWN)
41
+
42
+ fill(color: 'white')
43
+
44
+ smalrubot_v3.stop
45
+ end
46
+
47
+ if Input.key_down?(K_LEFT)
48
+ fill(color: 'white')
49
+ draw_font(string: '左に旋回する', color: 'black')
50
+
51
+ smalrubot_v3.turn_left
52
+
53
+ await until !Input.key_down?(K_LEFT)
54
+
55
+ fill(color: 'white')
56
+
57
+ smalrubot_v3.stop
58
+ end
59
+
60
+ if Input.key_down?(K_RIGHT)
61
+ fill(color: 'white')
62
+ draw_font(string: '右に旋回する', color: 'black')
63
+
64
+ smalrubot_v3.turn_right
65
+
66
+ await until !Input.key_down?(K_RIGHT)
67
+
68
+ fill(color: 'white')
69
+
70
+ smalrubot_v3.stop
71
+ end
72
+
73
+ if Input.key_down?(K_W) || Input.key_down?(K_S)
74
+ if Input.key_down?(K_W)
75
+ smalrubot_v3.left_motor.speed += 10
76
+ else
77
+ smalrubot_v3.left_motor.speed -= 10
78
+ end
79
+
80
+ fill(color: 'white')
81
+ draw_font(string: "左の速度: #{smalrubot_v3.left_motor.speed}%",
82
+ color: 'black')
83
+ end
84
+
85
+ if Input.key_down?(K_O) || Input.key_down?(K_L)
86
+ if Input.key_down?(K_O)
87
+ smalrubot_v3.right_motor.speed += 10
88
+ else
89
+ smalrubot_v3.right_motor.speed -= 10
90
+ end
91
+
92
+ fill(color: 'white')
93
+ draw_font(string: "右の速度: #{smalrubot_v3.right_motor.speed}%",
94
+ color: 'black')
95
+ end
96
+
97
+ if Input.key_down?(K_SPACE)
98
+ fill(color: 'white')
99
+ draw_font(string: '赤色LEDを光らせる', color: 'black')
100
+
101
+ smalrubot_v3.red_led.turn_on
102
+
103
+ sleep(1)
104
+
105
+ smalrubot_v3.red_led.turn_off
106
+
107
+ fill(color: 'white')
108
+ draw_font(string: '緑色LEDを光らせる', color: 'black')
109
+
110
+ smalrubot_v3.green_led.turn_on
111
+
112
+ sleep(1)
113
+
114
+ smalrubot_v3.green_led.turn_off
115
+ end
116
+
117
+ if Input.key_down?(K_B)
118
+ until !Input.key_down?(K_B)
119
+ fill(color: 'white')
120
+ draw_font(string: "光センサーの情報: #{smalrubot_v3.light_sensor.value}",
121
+ color: 'black')
122
+ await
123
+ end
124
+ fill(color: 'white')
125
+ end
126
+
127
+ if Input.key_down?(K_H)
128
+ until !Input.key_down?(K_H)
129
+ fill(color: 'white')
130
+ msg = 'タッチセンサーの情報: ' +
131
+ "左 #{smalrubot_v3.left_touch_sensor.on? ? 'ON ' : 'OFF'} " +
132
+ "右 #{smalrubot_v3.right_touch_sensor.on? ? 'ON ' : 'OFF'}"
133
+ draw_font(string: msg, color: 'black')
134
+ await
135
+ end
136
+ fill(color: 'white')
137
+ end
138
+ end
139
+ end
140
+
141
+ stage1.on(:key_push, K_A) do
142
+ loop do
143
+ fill(color: 'white')
144
+ draw_font(string: '自動運転', color: 'black')
145
+
146
+ if smalrubot_v3.left_touch_sensor.on? && smalrubot_v3.right_touch_sensor.on?
147
+ fill(color: 'white')
148
+ draw_font(string: '前方障害物発見!', color: 'black')
149
+
150
+ smalrubot_v3.backward(sec: 0.5)
151
+ if rand(2) == 1
152
+ smalrubot_v3.turn_left(sec: 0.2)
153
+ else
154
+ smalrubot_v3.turn_right(sec: 0.2)
155
+ end
156
+
157
+ next
158
+ end
159
+
160
+ if smalrubot_v3.right_touch_sensor.on?
161
+ fill(color: 'white')
162
+ draw_font(string: '右側障害物発見!', color: 'black')
163
+
164
+ smalrubot_v3.backward(sec: 0.5)
165
+ smalrubot_v3.turn_left(sec: 0.2)
166
+
167
+ next
168
+ end
169
+
170
+ if smalrubot_v3.left_touch_sensor.on?
171
+ fill(color: 'white')
172
+ draw_font(string: '左側障害物発見!', color: 'black')
173
+
174
+ smalrubot_v3.backward(sec: 0.5)
175
+ smalrubot_v3.turn_right(sec: 0.2)
176
+
177
+ next
178
+ end
179
+
180
+ smalrubot_v3.forward(sec: 0.5)
181
+
182
+ if Input.key_down?(K_Y)
183
+ fill(color: 'white')
184
+ break
185
+ end
186
+ end
187
+ end
@@ -16,19 +16,11 @@ frog1 = Character.new(costume: 'frog1.png', x: 300, y: 200, visible: false)
16
16
  stage1.on(:start) do
17
17
  draw_font(string: DESCRIPTION, color: 'black')
18
18
 
19
- button('D3').not_use_pullup
20
-
21
- if button('D3').up?
22
- frog1.visible = false
23
- else
24
- frog1.visible = true
19
+ loop do
20
+ if button('D3').up?
21
+ frog1.visible = false
22
+ else
23
+ frog1.visible = true
24
+ end
25
25
  end
26
26
  end
27
-
28
- stage1.on(:button_down, 'D3') do
29
- frog1.visible = true
30
- end
31
-
32
- stage1.on(:button_up, 'D3') do
33
- frog1.visible = false
34
- end
@@ -16,9 +16,9 @@ stage1.on(:start) do
16
16
  draw_font(string: DESCRIPTION, color: 'black')
17
17
 
18
18
  loop do
19
- led('D13').on
19
+ led('D13').turn_on
20
20
  sleep(1)
21
- led('D13').off
21
+ led('D13').turn_off
22
22
  sleep(1)
23
23
  end
24
24
  end
@@ -17,13 +17,13 @@ stage1.on(:start) do
17
17
  draw_font(string: DESCRIPTION, color: 'black')
18
18
 
19
19
  loop do
20
- rgb_led_anode('D3').on(color: 'red')
20
+ rgb_led_anode('D3').color = 'red'
21
21
  sleep(1)
22
- rgb_led_anode('D3').on(color: 'green')
22
+ rgb_led_anode('D3').color = 'green'
23
23
  sleep(1)
24
- rgb_led_anode('D3').on(color: 'blue')
24
+ rgb_led_anode('D3').color = 'blue'
25
25
  sleep(1)
26
- rgb_led_anode('D3').off
26
+ rgb_led_anode('D3').turn_off
27
27
  sleep(1)
28
28
  end
29
29
  end
@@ -17,13 +17,13 @@ stage1.on(:start) do
17
17
  draw_font(string: DESCRIPTION, color: 'black')
18
18
 
19
19
  loop do
20
- rgb_led_cathode('D3').on(color: 'red')
20
+ rgb_led_cathode('D3').color = 'red'
21
21
  sleep(1)
22
- rgb_led_cathode('D3').on(color: 'green')
22
+ rgb_led_cathode('D3').color = 'green'
23
23
  sleep(1)
24
- rgb_led_cathode('D3').on(color: 'blue')
24
+ rgb_led_cathode('D3').color = 'blue'
25
25
  sleep(1)
26
- rgb_led_cathode('D3').off
26
+ rgb_led_cathode('D3').turn_off
27
27
  sleep(1)
28
28
  end
29
29
  end
@@ -6,19 +6,21 @@ init_hardware
6
6
 
7
7
  stage1 = Stage.new(color: 'white')
8
8
 
9
- stage1.on(:sensor_change, 'A0') do |value|
10
- v = sensor('A0').value
11
- if 0 <= v && v <= 255
12
- fill(color: 'red')
13
- end
9
+ stage1.on(:start) do
10
+ loop do
11
+ v = sensor('A0').value
12
+ if 0 <= v && v <= 255
13
+ fill(color: 'red')
14
+ end
14
15
 
15
- if 256 <= v && v <= 511
16
- fill(color: 'yellow')
17
- end
16
+ if 256 <= v && v <= 511
17
+ fill(color: 'yellow')
18
+ end
18
19
 
19
- if 512 <= v
20
- fill(color: 'blue')
21
- end
20
+ if 512 <= v
21
+ fill(color: 'blue')
22
+ end
22
23
 
23
- draw_font(string: "センサーの情報:#{v}", color: 'black')
24
+ draw_font(string: "センサーの情報:#{v}", color: 'black')
25
+ end
24
26
  end
data/smalruby.gemspec CHANGED
@@ -42,5 +42,5 @@ Gem::Specification.new do |spec|
42
42
  else
43
43
  spec.add_runtime_dependency 'dxruby_sdl', '~> 0.0.12'
44
44
  end
45
- spec.add_runtime_dependency 'smalrubot', '~> 0.0.1'
45
+ spec.add_runtime_dependency 'smalrubot', '~> 0.0.2'
46
46
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smalruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: x86-mingw32
6
6
  authors:
7
7
  - Kouji Takao
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-21 00:00:00.000000000 Z
11
+ date: 2015-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -198,14 +198,14 @@ dependencies:
198
198
  requirements:
199
199
  - - ~>
200
200
  - !ruby/object:Gem::Version
201
- version: 0.0.1
201
+ version: 0.0.2
202
202
  type: :runtime
203
203
  prerelease: false
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
206
  - - ~>
207
207
  - !ruby/object:Gem::Version
208
- version: 0.0.1
208
+ version: 0.0.2
209
209
  description: smalruby is a 2D game development library. This is part of "Smalruby"
210
210
  project that is a learning ruby programming environment for kids.
211
211
  email:
@@ -265,6 +265,7 @@ files:
265
265
  - lib/smalruby/hardware/rgb_led_cathode.rb
266
266
  - lib/smalruby/hardware/sensor.rb
267
267
  - lib/smalruby/hardware/servo.rb
268
+ - lib/smalruby/hardware/smalrubot_v3.rb
268
269
  - lib/smalruby/hardware/two_wheel_drive_car.rb
269
270
  - lib/smalruby/stage.rb
270
271
  - lib/smalruby/util.rb
@@ -276,13 +277,13 @@ files:
276
277
  - samples/car.rb
277
278
  - samples/cat.rb
278
279
  - samples/check_hardware_motor_driver.rb
280
+ - samples/check_hardware_smalrubot_v3.rb
279
281
  - samples/console.rb
280
282
  - samples/costume.rb
281
283
  - samples/costumes.rb
282
284
  - samples/extra_car.png
283
285
  - samples/finding_cars.rb
284
286
  - samples/hardware_button.rb
285
- - samples/hardware_button_with_pullup.rb
286
287
  - samples/hardware_led.rb
287
288
  - samples/hardware_motor_driver.rb
288
289
  - samples/hardware_rgb_led_anode.rb
@@ -1,32 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- DESCRIPTION = <<EOS
4
- ハードウェアのボタン(プルアップ)を操作します
5
- EOS
6
-
7
- # デジタルの3番ピンに直接ボタンを接続してください。
8
-
9
- require 'smalruby'
10
-
11
- init_hardware
12
-
13
- stage1 = Stage.new(color: 'white')
14
- frog1 = Character.new(costume: 'frog1.png', x: 300, y: 200, visible: false)
15
-
16
- stage1.on(:start) do
17
- draw_font(string: DESCRIPTION, color: 'black')
18
-
19
- if button('D3').up?
20
- frog1.visible = false
21
- else
22
- frog1.visible = true
23
- end
24
- end
25
-
26
- stage1.on(:button_down, 'D3') do
27
- frog1.visible = true
28
- end
29
-
30
- stage1.on(:button_up, 'D3') do
31
- frog1.visible = false
32
- end