In this training, you will learn the basics of the Internet of Things. In the second part you will learn how to program Raspberry Pi to send commands to the GPIO.
Sense_hat temperature program:
from sense_emu import SenseHat
sense = SenseHat()
red = (255, 0, 0)
blue = (0, 0, 255)
while True:
temp = sense.temp
pixels = [red if i < temp else blue for i in range(64)]
sense.set_pixels(pixels)
Sense_hat humidity program:
from sense_emu import SenseHat
sense = SenseHat()
green = (0, 255, 0)
white = (255, 255, 255)
while True:
humidity = sense.humidity
humidity_value = 64 * humidity / 100
pixels = [green if i < humidity_value else white for i in range(64)]
sense.set_pixels(pixels)
Sense_hat Hello World program:
from sense_emu import SenseHat
sense_emulator = SenseHat()
sense_emulator.show_message('Hello World')
Flash the LED
from gpiozero import LED
led = LED(7)
led.blink(1,1,15)
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(7, GPIO.OUT)
GPIO.output(7, GPIO.HIGH)
time.sleep(2)
GPIO.output(7, GPIO.LOW)
time.sleep(2)
GPIO.output(7, GPIO.HIGH)
time.sleep(2)
GPIO.output(7, GPIO.LOW)
0 comment