Skip to content

Instantly share code, notes, and snippets.

@sh4869 sh4869/Test_serial.ino
Last active Aug 13, 2016

Embed
What would you like to do?
Rubyでserialportを弄る簡単なスクリプト
char ch = 'R'; //送受信の時に使う文字列。
int i = 1;
void setup()
{
Serial.begin(9600);
pinMode(13,OUTPUT);
}
void loop()
{
while(Serial.available()){
ch = Serial.read();
if(ch == 'y'){
digitalWrite(13,HIGH);
}
if(ch == 'n'){
digitalWrite(13,LOW);
}
}
}
require 'rubygems'
require 'serialport'
@serial_port = "/dev/ttyACM0" #シリアルのポートを指定。OSによって違うので確認のこと。
@serial_bps = 9600
sp = SerialPort.new(@serial_port,@serial_bps)
count = 0
loop do
sp.write('y') #serialへの書き込み
sleep(2)
sp.write('n')
sleep(2)
if count == 20
break
end
count += 1
puts "#{count}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.