Created
March 16, 2010 07:00
-
-
Save tatsuro-ueda/333716 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
#encoding: utf-8 | |
require 'miyako' | |
include Miyako | |
require "wincom" | |
require 'miyako_temp_lib' | |
# 初期化ここから | |
comp1 = Serial.new | |
comp1.open(5,0x0000,9600,8,0,0,256,256) | |
comp1.send("AT\r\n") | |
string_stored = "" | |
temp = 0 | |
font = Font.sans_serif | |
# 初期化ここまで | |
Miyako.main_loop do | |
break if Input.quit_or_escape? # ESC等で終了 | |
string_stored = update_string_stored(comp1, string_stored) # シリアルポートから読込 | |
if string_stored =~ /.*\n/ # 末尾が改行なら | |
temp = string_stored.chomp!("\r\n").to_f * 5.0 / 1024 * 100 # 温度を更新 | |
string_stored = "" # 文字列をクリア | |
end | |
font.size = 60; font.draw_text(Screen, "現在の温度:#{sprintf("%3.1f", temp)}℃", 20, 50) # 温度を文字で描画 | |
Drawing.rect(Screen, [20, 225, temp * 20, 50], [255, 0, 0], true) # 温度を図形で描画 | |
draw_frame(font) # 目盛を描画 | |
end |
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
def update_string_stored(comp1, string_stored) | |
string_recieved = comp1.receive | |
if string_recieved == nil | |
string_stored | |
else | |
string_stored << string_recieved | |
end | |
end | |
def draw_frame(font) | |
font.size = 30 | |
for i in 0..30 do | |
if i % 5 == 0 | |
Drawing.line(Screen, [20 + i * 20, 200, 0, 100], [255, 255, 255], true) | |
font.draw_text(Screen, i.to_s, 5 + i * 20, 170) | |
else | |
Drawing.line(Screen, [20 + i * 20, 200, 0, 100], [0, 255, 0], true) | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment