Sha256: deb3b042f4a4b394e06d5e63a07d48dcfdd39372375877f6ca925f44f0e48488
Contents?: true
Size: 722 Bytes
Versions: 7
Compression:
Stored size: 722 Bytes
Contents
# # Example of how to use the DHT class for DHT 11 and DHT 22 sensors. # require 'bundler/setup' require 'denko' board = Denko::Board.new(Denko::Connection::Serial.new) dht = Denko::Sensor::DHT.new(pin: 5, board: board) # The DHT class pre-processes raw data from the board. When it reaches callbacks # it's already hash of :temperature and :humidity keys, both with Float values. dht.add_callback do |reading| print "#{Time.now.strftime '%Y-%m-%d %H:%M:%S'} | " if reading[:error] puts "Error: #{reading[:error]}" else print "#{reading[:celsius]} \xC2\xB0C | #{reading[:fahrenheit]} \xC2\xB0F | " puts "#{reading[:humidity]}% relative humidity" end end # Read it every 5 seconds. dht.poll(5) sleep
Version data entries
7 entries across 7 versions & 1 rubygems