Guest User

Untitled

a guest
Mar 23rd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. # ライブラリのインストール
  2. # gem install serialport
  3.  
  4. require 'io/console'
  5. require 'serialport'
  6.  
  7.  
  8. sp = SerialPort.new('/dev/ttyS0', 9600, 8, 1, 0) # device, rate, data, stop, parity
  9. puts "Angle( C-c: exit )\n1. 0°\n2. 90°\n3. 180°"
  10.  
  11. # ArduinoからのAngle情報受信ループ
  12. while angle_str = sp.readline.chomp.strip
  13. if angle_str
  14.  
  15. # ユーザのコマンド選択ループ
  16. while c = STDIN.getch
  17. exit if c == ?\C-c
  18.  
  19.     # キーのValidation
  20. if c == "1" || c == "2" || c == "3"
  21. # ファイル書き込み
  22. File.open("./data.txt", "a") do |f|
  23. f.puts("angle,#{angle_str},feel,#{c}");
  24. end
  25.  
  26.  
  27. print c
  28. puts "\nAngle( C-c: exit )\n1. 0°\n2. 90°\n3. 180°"
  29. sp.puts(c) #ユーザの入力をArduinoに送信
  30.  
  31. # コマンド選択ループ脱出
  32. break
  33. else
  34. puts "Prease choose 1-3 number"
  35. end
  36. end
  37.  
  38. end
  39. end
Add Comment
Please, Sign In to add comment