Last active
December 11, 2015 23:08
-
-
Save fukayatsu/4674297 to your computer and use it in GitHub Desktop.
LM35で室温を測ってみた時のコード
This file contains hidden or 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
| require 'dino' | |
| VCC = 5.0 | |
| VOLTS_PER_TEMP = 0.01 | |
| DATA_MAX = 1024 | |
| board = Dino::Board.new(Dino::TxRx.new) | |
| sensor = Dino::Components::Sensor.new(pin: 'A2', board: board) | |
| dataset = [] | |
| on_data = Proc.new do |data| | |
| dataset << data.to_i | |
| if (dataset.size >= 64) | |
| temperature = dataset.inject(:+).to_f / dataset.size / DATA_MAX / VOLTS_PER_TEMP * VCC | |
| puts "%2.1f度" % temperature | |
| dataset = [] | |
| # sleep 1 | |
| end | |
| end | |
| sensor.when_data_received(on_data) | |
| sleep |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment