Skip to content

Instantly share code, notes, and snippets.

@nasajpledu
nasajpledu / codingedl_step2-1
Last active June 19, 2021 20:26
Code a Mars Landing - Step 2: Import Your Components
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")
@nasajpledu
nasajpledu / codingedl_step3-2
Created February 9, 2021 18:07
Code a Mars Landing - Step 3: Set up an ultrasonic sensor
while True:
distance = ultrasonic.distance
print(distance)
sleep(0.1)
@nasajpledu
nasajpledu / codingedl_step3-3
Created February 9, 2021 18:08
Code a Mars Landing - Step 3: Add a light indicator
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()
@nasajpledu
nasajpledu / codingedl_step4-1
Created February 9, 2021 18:14
Code a Mars Landing - Step 4: Transition between stages
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()
@nasajpledu
nasajpledu / codingedl_step5-1
Created February 9, 2021 18:17
Code a Mars Landing - Step 5: Collect sunlight
from components import LightSensor
from time import sleep, time
light = LightSensor("D6")
while True:
lightlevel = (light.reading)
print lightlevel
@nasajpledu
nasajpledu / codingedl_step5-2
Created February 9, 2021 18:18
Code a Mars Landing - Step 5: Plot your solar-power data
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")
@nasajpledu
nasajpledu / codingedl_step6-1
Created February 9, 2021 18:20
Code a Mars Landing - Step 6: Send a message using sound
from components import Button
button = Button("D7")
while True:
if button.is_pressed:
buzzer.on()
else:
buzzer.off()
@nasajpledu
nasajpledu / codingedl_step6-2
Created February 9, 2021 18:21
Code a Mars Landing: Step 6: Send your message in code
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 != ' ':
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()
#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)