diff --git a/kitronic_06.py b/kitronic_06.py index cce4dc0..50790bf 100644 --- a/kitronic_06.py +++ b/kitronic_06.py @@ -10,6 +10,7 @@ class Main: def __init__(self): self._debounce = {BUTTON_A: False, BUTTON_B: False} self._buttons = {BUTTON_A: button_a, BUTTON_B: button_b} + music.set_tempo(ticks=4, bpm=145) def main(self): while True: diff --git a/kitronic_09.py b/kitronic_09.py new file mode 100644 index 0000000..275b95d --- /dev/null +++ b/kitronic_09.py @@ -0,0 +1,35 @@ +from microbit import * + + +def main(): + while True: + charge = pin0.read_analog() / 10 + if charge >= 95: + pin1.write_digital(1) + pin2.write_digital(1) + pin8.write_digital(1) + pin12.write_digital(1) + elif charge >= 75: + pin1.write_digital(1) + pin2.write_digital(1) + pin8.write_digital(1) + pin12.write_analog(int((charge - 75) / 25 * 1023)) + elif charge >= 50: + pin1.write_digital(1) + pin2.write_digital(1) + pin8.write_analog(int((charge - 50) / 25 * 1023)) + pin12.write_digital(0) + elif charge >= 25: + pin1.write_digital(1) + pin2.write_analog(int((charge - 25) / 25 * 1023)) + pin8.write_digital(0) + pin12.write_digital(0) + else: + pin1.write_analog(int(charge / 25 * 1023)) + pin2.write_digital(0) + pin8.write_digital(0) + pin12.write_digital(0) + + +if __name__ == "__main__": + main()