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.1-x86-mingw32 samples/hardware_two_wheel_drive_car.rb
smalruby-0.1.1 samples/hardware_two_wheel_drive_car.rb
smalruby-0.1.0-x86-mingw32 samples/hardware_two_wheel_drive_car.rb
smalruby-0.1.0 samples/hardware_two_wheel_drive_car.rb
smalruby-0.0.32-x86-mingw32 samples/hardware_two_wheel_drive_car.rb
smalruby-0.0.32 samples/hardware_two_wheel_drive_car.rb
smalruby-0.0.31-x86-mingw32 samples/hardware_two_wheel_drive_car.rb
smalruby-0.0.31 samples/hardware_two_wheel_drive_car.rb
smalruby-0.0.30-x86-mingw32 samples/hardware_two_wheel_drive_car.rb
smalruby-0.0.30 samples/hardware_two_wheel_drive_car.rb