Sha256: bae574f773ab9df235911b264f08677f6d86c0022452ed1b6acac3a25c4d6f8d

Contents?: true

Size: 1.62 KB

Versions: 30

Compression:

Stored size: 1.62 KB

Contents

# -*- coding: utf-8 -*-

DESCRIPTION = <<EOS
2WD車のタイヤ(モーター)を操作します
EOS

# PWM出力可能なデジタルの5番・6番ピンに左のモーター、10番・9番ピンに右
# のモーターを接続してください。

require 'smalruby'

init_hardware

stage1 = Stage.new(color: 'white')

stage1.on(:start) do
  draw_font(string: DESCRIPTION, color: 'black')

  loop do
    two_wheel_drive_car('D5').forward
    sleep(2)
    two_wheel_drive_car('D5').backward
    sleep(2)
    two_wheel_drive_car('D5').turn_left
    sleep(0.5)
    two_wheel_drive_car('D5').turn_right
    sleep(0.5)
    two_wheel_drive_car('D5').stop
    sleep(1)
  end
end

stage1.on(:key_push, K_E) do
  two_wheel_drive_car('D5').left_speed += 1

  fill(color: 'white')
  draw_font(string: "速度%: 左< #{two_wheel_drive_car('D5').left_speed} > 右< #{two_wheel_drive_car('D5').right_speed} >", color: 'black')
end

stage1.on(:key_push, K_D) do
  two_wheel_drive_car('D5').left_speed -= 1

  fill(color: 'white')
  draw_font(string: "速度%: 左< #{two_wheel_drive_car('D5').left_speed} > 右< #{two_wheel_drive_car('D5').right_speed} >", color: 'black')
end

stage1.on(:key_push, K_UP) do
  two_wheel_drive_car('D5').right_speed += 1

  fill(color: 'white')
  draw_font(string: "速度%: 左< #{two_wheel_drive_car('D5').left_speed} > 右< #{two_wheel_drive_car('D5').right_speed} >", color: 'black')
end

stage1.on(:key_push, K_DOWN) do
  two_wheel_drive_car('D5').right_speed -= 1

  fill(color: 'white')
  draw_font(string: "速度%: 左< #{two_wheel_drive_car('D5').left_speed} > 右< #{two_wheel_drive_car('D5').right_speed} >", color: 'black')
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
smalruby-0.1.11-x86-mingw32 samples/hardware_two_wheel_drive_car.rb
smalruby-0.1.11 samples/hardware_two_wheel_drive_car.rb
smalruby-0.1.10-x86-mingw32 samples/hardware_two_wheel_drive_car.rb
smalruby-0.1.10 samples/hardware_two_wheel_drive_car.rb
smalruby-0.1.9-x86-mingw32 samples/hardware_two_wheel_drive_car.rb
smalruby-0.1.9 samples/hardware_two_wheel_drive_car.rb
smalruby-0.1.8-x86-mingw32 samples/hardware_two_wheel_drive_car.rb
smalruby-0.1.8 samples/hardware_two_wheel_drive_car.rb
smalruby-0.1.7-x86-mingw32 samples/hardware_two_wheel_drive_car.rb
smalruby-0.1.7 samples/hardware_two_wheel_drive_car.rb
smalruby-0.1.6-x86-mingw32 samples/hardware_two_wheel_drive_car.rb
smalruby-0.1.6 samples/hardware_two_wheel_drive_car.rb
smalruby-0.1.5-x86-mingw32 samples/hardware_two_wheel_drive_car.rb
smalruby-0.1.5 samples/hardware_two_wheel_drive_car.rb
smalruby-0.1.4-x86-mingw32 samples/hardware_two_wheel_drive_car.rb
smalruby-0.1.4 samples/hardware_two_wheel_drive_car.rb
smalruby-0.1.3-x86-mingw32 samples/hardware_two_wheel_drive_car.rb
smalruby-0.1.3 samples/hardware_two_wheel_drive_car.rb
smalruby-0.1.2-x86-mingw32 samples/hardware_two_wheel_drive_car.rb
smalruby-0.1.2 samples/hardware_two_wheel_drive_car.rb