Last active
March 9, 2017 08:56
-
-
Save naclyhara/e5197a8191eb22ae36aff97ad71b4533 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module EV3 | |
module UiWriteSubcodes | |
LED = 27 # ev3sources/lms2012/lms2012/source/bytecodes.h | |
end | |
module Commands | |
class UiWrite < Base | |
UI_WRITE_SUBCODES__LED = 27 | |
# color: 0-9 | |
def set_led(color) | |
if !color.is_a?(Integer) || !(0..9).include?(color) | |
raise "invalid color: #{color.inspect}" | |
end | |
@message += | |
ByteCodes::UI_WRITE.bytes + | |
[UiWriteSubcodes::LED] + | |
[color] | |
return self | |
end | |
end | |
end | |
class Brick | |
def set_led(color) | |
Commands::UiWrite.new(@connection). | |
set_led(color). | |
command_type(CommandType::DIRECT_COMMAND_NO_REPLY). | |
send_command | |
end | |
end | |
end | |
# usage: | |
# @brick.set_led(6) | |
# | |
=begin | |
LED_BLACK = 0, <- turn off LED | |
LED_GREEN = 1, | |
LED_RED = 2, | |
LED_ORANGE = 3, | |
LED_GREEN_FLASH = 4, | |
LED_RED_FLASH = 5, | |
LED_ORANGE_FLASH = 6, | |
LED_GREEN_PULSE = 7, | |
LED_RED_PULSE = 8, | |
LED_ORANGE_PULSE = 9, | |
Refereces: | |
- http://analyticphysics.com/Diversions/Assembly%20Language%20Programming%20for%20LEGO%20Mindstorms%20EV3.htm | |
- EV3 Firmware Developer Kit documentation | |
https://education.lego.com/en-us/support/mindstorms-ev3/developer-kits | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment