Workbook 1 - Introduction to Kookaberry
Parts 1-4
(print, display, variables, buttons, while loops)
# This is a comment
from connectedcode import *
# Print to the console
print("Hello world")
# Print to the console using a variable
name = "Jack"
print(name)
print("Hello", name)
# Print to the Kookaberry display
display.print("Kookaberry")
display.print("Hello", name)
# Print to a specific position on the Kookaberry display
display.print_at_position(2, 7, "bottom text")
display.print_at_position(2, 7, "lower words")
# Flash each LED for a second.
led_green.on()
sleep(1)
led_green.off()
led_orange.on()
sleep(1)
led_orange.off()
led_red.on()
sleep(1)
led_red.off()
# Loop forever
while True:
# Print hello, then sleep for a second.
display.print("Hello")
sleep(1)
# Check if button A was pressed
if button_a.was_pressed():
# if it was, say that, then wait for a second.
display.print("Button A was pressed")
sleep(1)
else:
# Otherwise, clear the display.
display.clear()
Parts 5 - repeat after me
(combine previous concepts + for loops)
from connectedcode import *
# Create the presses as an empty string
presses = ""
# Loop forever
while True:
# Check if each button was pressed
# And add the matching letter to the presses string
if button_a.was_pressed():
presses = presses + "a"
if button_b.was_pressed():
presses = presses + "b"
if button_d.was_pressed():
presses = presses + "c"
# Clear the display, then show the new presses
display.clear()
display.print(presses)
# Once button C is pressed...
if button_c.was_pressed():
# Loop through each letter in presses
for letter in presses:
# Flash the matching LED for half a second
if letter == "a":
led_red.on()
sleep(0.5)
led_red.off()
if letter == "b":
led_green.on()
sleep(0.5)
led_green.off()
if letter == "d":
led_orange.on()
sleep(0.5)
led_orange.off()
# Reset presses to empty, to reset the game.
presses = ""
Workbook 2 - Radio
(Set up radio, send & receive messages)
from connectedcode import *
# Store your team name in the variable called channel
channel = "Team_Renee_and_Jack"
# Set up radio and set the correct channel
radio = connect_radio()
radio.set_channel(channel)
# Send a message over the radio
radio.send_message("Hello")
# Continually check for new radio messages
# If there is a message print it out.
while True:
message = radio.get_message()
if message:
display.print(message)
Workbook 3 - Sensors
(set up sensors, calibrate, take measurements)
from connectedcode import *
# Set up and calibrate sensors
cubesat_sensors = connect_sensors()
cubesat_sensors.calibrate()
# Make your program run continuously
while True:
# Take measurements and store them in variables
altitude = cubesat_sensors.get_altitude()
temp = cubesat_sensors.get_temperature()
pressure = cubesat_sensors.get_pressure()
acceleration = cubesat_sensors.get_acceleration()
# Display your measurements on the screen
display.print(f'Altitude: {altitude} m')
display.print(f'Temp: {temp} c')
display.print(f'Press: {pressure} hPa')
display.print(f'Accel: {acceleration} g')
sleep(0.5)
Workbook 4 - Logging & Graphing
(set up sensors, calibrate, take measurements)
from connectedcode import *
# Create a variables to store your team name and the headers for your file
team_name = "Team_Renee_and_Jack"
headers = "time,altitude"
# Use the header variable to start the logger
logger = start_logger(team_name, headers)
# Set up and calibrate the sensors
cubesat_sensors = connect_sensors()
cubesat_sensors.calibrate()
# The main code loop where altitude measurements will be logged every second
while True:
# Measure the altitude
altitude = cubesat_sensors.get_altitude()
# get and print the time
current_time = seconds_since_start()
display.print(f"Time: {current_time} sec")
# print the altitude
display.print(f"Alt: {altitude} m")
# Create a variable that stores the data, formatted correctly for logging. Then log the data.
data = f"{current_time},{altitude}"
logger.log(data)
# Keep checking the time every 0.1 seocnds (in another while loop)
# until 1 second has passed since the last time current_time was set
while seconds_since_start() == current_time:
sleep(0.1)
display.clear()