Last active
November 25, 2016 00:07
-
-
Save ojisan/6fe31d1786118a3d89712e1042c01797 to your computer and use it in GitHub Desktop.
motor
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
#!mruby | |
@Uart = Serial.new(4, 230400)#//TX/RX:pin12/pin11, baud rate: 230400 | |
def set_up() | |
#//L Motor PinSET | |
pinMode(14, 1) | |
pinMode(15, 1) | |
#//R Motor PinSET | |
pinMode(16, 1) | |
pinMode(17, 1) | |
end | |
def motor_stop() | |
pwm(14, 0) | |
pwm(15,0) | |
pwm(16, 0) | |
pwm(17, 0) | |
end | |
def l_motorf() | |
pwm(14, 0) | |
pwm(15, 255) | |
end | |
def l_motorb() | |
pwm(14, 255) | |
pwm(15, 0) | |
end | |
def r_motorf() | |
pwm(16, 0) | |
pwm(17, 255) | |
end | |
def r_motorb() | |
pwm(16, 255) | |
pwm(17, 0) | |
end | |
@Uart.println("setup") | |
set_up() | |
motor_stop() | |
#//while (true) do | |
2000.times do | |
led 1 | |
#//繝・・繧ソ蜿嶺ソ。 | |
if (@Uart.available())then #//蜿嶺ソ。繝・・繧ソ縺後≠繧区凾 | |
readc = @Uart.read() #//1譁・ュ苓ェュ縺ソ霎シ縺ソ | |
#//FF | |
if(readc =="f")then | |
l_motorf() | |
r_motorf() | |
@Uart.println("motor FF") | |
end | |
#//Back | |
if(readc =="b")then | |
l_motorb() | |
r_motorb() | |
@Uart.println("motor back") | |
end | |
#//L | |
if(readc =="l")then | |
l_motorb() | |
r_motorf() | |
@Uart.println("motor left") | |
end | |
#//R | |
if(readc =="r")then | |
l_motorf() | |
r_motorb() | |
@Uart.println("motor right") | |
end | |
#//STOP | |
if(readc =="s")then | |
motor_stop() | |
@Uart.println("motor stop") | |
end | |
end | |
led 0 | |
delay(100) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment