Last active
December 11, 2015 23:08
-
-
Save fukayatsu/4674094 to your computer and use it in GitHub Desktop.
njl7502lと抵抗50Ωぐらいで室内光を測ってみたときのコード
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
require 'dino' | |
board = Dino::Board.new(Dino::TxRx.new) | |
sensor = Dino::Components::Sensor.new(pin: 'A0', board: board) | |
dataset = [] | |
on_data = Proc.new do |data| | |
dataset << data.to_i | |
if (dataset.size >= 64) | |
puts dataset.inject(:+) / dataset.size | |
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