Skip to content

Commit

Permalink
Microbit Projects
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahmakowski committed Dec 4, 2023
1 parent b2b80e4 commit 60ca3b9
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
65 changes: 65 additions & 0 deletions src/microbit/Smart_Watch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from microbit import *
import music
import time

current_hrs = 21
current_mins = 47
prev_ms = time.ticks_ms()

def change_time():
music.play(music.BA_DING)
display.clear()
global current_hrs, current_mins, prev_ms
display.scroll('Change Time')
current_hrs = 0
current_mins = 0
display.scroll('Hrs:')
while not button_b.is_pressed():
display.scroll(current_hrs)
if button_a.was_pressed():
current_hrs += 1
if current_hrs >= 24:
current_hrs = 0

display.scroll('Mins:')
while not button_b.is_pressed():
display.scroll(current_mins)
if button_a.was_pressed() or button_a.is_pressed():
current_mins += 1
if current_mins >= 60:
current_mins = 0
prev_ms = time.ticks_ms()
display.scroll('Confirmed')

def show_time():
display.clear()
music.play(music.BA_DING)
display.scroll('{}:{}'.format(current_hrs, current_mins))

def show_temp():
display.clear()
music.play(music.BA_DING)
display.scroll('{}'.format(temperature()))

def do_time():
global prev_ms, current_hrs, current_mins
if abs(time.ticks_ms() - prev_ms) > 60000:
current_mins += 1
prev_ms += 60000
if current_mins > 60:
current_hrs += 1
current_mins = 0
if current_hrs > 24:
current_hrs = 0

while True:
if button_a.is_pressed() and button_b.is_pressed():
change_time()
elif button_a.is_pressed():
show_time()
elif button_b.is_pressed():
show_temp()

do_time()


23 changes: 23 additions & 0 deletions src/microbit/door-alarm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from microbit import *

active_mag = False

while True:
if compass.get_field_strength() < 200000:
active_mag = True
if button_a.is_pressed() and button_b.is_pressed():
display.scroll('Confirmed')
active_mag = False
active_light = False
elif button_a.is_pressed():
if active_mag:
display.set_pixel(0, 0, 9)
display.set_pixel(4, 4, 9)
display.set_pixel(0, 4, 9)
display.set_pixel(4, 0, 9)
else:
display.set_pixel(2, 2, 9)
while not button_b.is_pressed():
pass
display.clear()
sleep(10)

0 comments on commit 60ca3b9

Please sign in to comment.