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
from components import UltrasonicSensor, LED | |
from time import sleep | |
#If your kit doesn't automtically detect the port being used, you can specify | |
ultrasonic = UltrasonicSensor("D1") |
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
while True: | |
distance = ultrasonic.distance | |
print(distance) | |
sleep(0.1) |
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
red_led = LED("D2") | |
yellow_led = LED("D3") | |
green_led = LED("D4") | |
if distance < 10: | |
red_led.on() | |
yellow_led.on() | |
green_led.on() | |
elif distance < 20: | |
red_led.off() |
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
from components import Buzzer | |
buzzer = Buzzer("D5") | |
if distance < 10: | |
red_led.on() | |
yellow_led.on() | |
green_led.on() | |
buzzer.on() | |
elif distance < 20: | |
red_led.off() | |
yellow_led.on() |
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
from components import LightSensor | |
from time import sleep, time | |
light = LightSensor("D6") | |
while True: | |
lightlevel = (light.reading) | |
print lightlevel |
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
plt.ion() | |
fig = plt.figure() | |
x_data = [] | |
y_data = [] | |
start_time = time() | |
x_data.append(elapsed_time) | |
y_data.append(lightlevel) | |
plt.title("Light Sensor input over time") |
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
from components import Button | |
button = Button("D7") | |
while True: | |
if button.is_pressed: | |
buzzer.on() | |
else: | |
buzzer.off() |
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
Morse_Dict = { 'A':'.-', 'B':'-...', 'C':'-.-.', 'D':'-..', 'E':'.', | |
'F':'..-.', 'G':'--.', 'H':'....', 'I':'..', 'J':'.---', 'K':'-.-', | |
'L':'.-..', 'M':'--', 'N':'-.', 'O':'---', 'P':'.--.', 'Q':'--.-', | |
'R':'.-.', 'S':'...', 'T':'-', 'U':'..-', 'V':'...-', 'W':'.--', | |
'X':'-..-', 'Y':'-.--', 'Z':'--..'} | |
def encrypt(message): | |
convert = ' ' | |
for letter in message: | |
if letter != ' ': |
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
from gpiozero import LED | |
from ptprotoplus import adc | |
from time import sleep | |
from multiprocessing import Process | |
uvled = LED(4) | |
redled = LED(10) | |
irled = LED(11) | |
light = adc.ADCProbe() |
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
#create the window of specified size in which to display the game | |
self.game_screen = pygame.display.set_mode((width, height)) | |
#set the game window color to white | |
self.game_screen.fill(WHITE_COLOR) | |
pygame.display.set_caption(title) |
OlderNewer