Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # ライブラリのインストール
- # gem install serialport
- require 'io/console'
- require 'serialport'
- sp = SerialPort.new('/dev/ttyS0', 9600, 8, 1, 0) # device, rate, data, stop, parity
- puts "Angle( C-c: exit )\n1. 0°\n2. 90°\n3. 180°"
- # ArduinoからのAngle情報受信ループ
- while angle_str = sp.readline.chomp.strip
- if angle_str
- # ユーザのコマンド選択ループ
- while c = STDIN.getch
- exit if c == ?\C-c
- # キーのValidation
- if c == "1" || c == "2" || c == "3"
- # ファイル書き込み
- File.open("./data.txt", "a") do |f|
- f.puts("angle,#{angle_str},feel,#{c}");
- end
- print c
- puts "\nAngle( C-c: exit )\n1. 0°\n2. 90°\n3. 180°"
- sp.puts(c) #ユーザの入力をArduinoに送信
- # コマンド選択ループ脱出
- break
- else
- puts "Prease choose 1-3 number"
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment