Skip to content

Commit

Permalink
Merge pull request #9 from SquidSinker/SS/example
Browse files Browse the repository at this point in the history
Add example for environment sensors!
  • Loading branch information
aviks committed Oct 17, 2019
2 parents 7620f4b + 9be6bc1 commit 218cad5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Binary file added docs/src/sense_hat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions example/environmental.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# ## Environmental sensors with the SenseHat
# ### Reads and displays temperature, humidity and pressure.

using SenseHat

# Create channel to store stick events
c = Channel{StickEvent}(32)
@async while true
# Push every event into the channel
put!(c, readstick())
end

while true
# Retrieve events from channel
ev = take!(c)
if ev.direc == SenseHat.Stick.MIDDLE && ev.state == SenseHat.Stick.PRESS
# Flash the Julia logo on the display
LED[:] = SenseHat.JULIA_LOGO; sleep(1); led_clear()
# Display atmospheric pressure
show_message(string("P R E S S U R E:", round(Int, pressure()), "mb"), 0.08, colorant"purple")
# Display temperature
show_message(string("T E M P E R A T U R E:", round(Int, temperature()), "C"), 0.08, colorant"red")
# Display humidity
show_message(string("H U M I D I T Y:", round(Int, humidity()), "%"), 0.08, colorant"blue")
end
end

0 comments on commit 218cad5

Please sign in to comment.