Skip to content

Commit

Permalink
upload from mac
Browse files Browse the repository at this point in the history
  • Loading branch information
Taha Dhiaeddine Amdouni authored and Taha Dhiaeddine Amdouni committed Aug 14, 2017
1 parent c3c6f57 commit 538d07b
Show file tree
Hide file tree
Showing 1,814 changed files with 1,054,039 additions and 0 deletions.
21 changes: 21 additions & 0 deletions A-Shaky-Start-Talk-Timer/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Nigel Lester

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
24 changes: 24 additions & 0 deletions A-Shaky-Start-Talk-Timer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# A-Shaky-Start-Talk-Timer

This is a BBC micro:bit count down talk timer to tell you how much time you have left to complete your talk.

**You start the timer** by **shaking** the micro:bit. It gives you a visual indication as to the time left to give your talk. It starts counting down when you stop shaking it. Initially it lights all LEDs, and as time passes it progressively switches then off. When your time is up it displays a clock animation :-)

**To abandon a count down**, press button A when it is timing a talk.

**To set the duration** of the talk press button A.
* You **increment the talk length** in 1 min steps by pressing button B; and
* You **decrement the talk length** in 1 min steps by pressing button A.
* To **exit** this mode, press Button A for more than 2 seconds. It will then tell you the length of the talk, with 1 LED being lit per minute of the talk.

**When waiting to be shaken** it will tell you the length of the talk by lighting 1 LED per minute of the talk.

**Broadcasting to other microbits** - If you have other micro:bits with the "A-Shaky-Start-Talk-Timer" program it broadcasts a start message plus talk duration, which causes them to count down in the same way too - cool eh!

This is written in MicroPython.

**Debug mode** - If you press button B for more than 2 seconds whilst not counting down, this sets the timer into debug mode which sets the talk duration to 15 seconds. This will display as a single dimly lit LED. To exit debug mode, use button A to set a new talk duration.

**The radio message** being sent has the format "asstt COMMAND PAYLOAD" and is sent as a string. For the COMMAND start, the PAYLOAD is the talk length/25 (milliseconds) i.e. the delay to switch off each LED. The other COMMAND is stop and it has no PAYLOAD.

**A little trivia** - The first submit was made from a Chromebook on a train journey between Cromford to Nottingham when approaching Derby. Just after Derby I saw Britain’s rarest train, the “Flying Banana” aka the [New Measurement Train](https://en.wikipedia.org/wiki/New_Measurement_Train). Improvements to this help were subsquently made just after leaving Paddington having seen InterCity 125 engine 43003 (still looking out for 43002 which has the BR livery).
227 changes: 227 additions & 0 deletions A-Shaky-Start-Talk-Timer/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""A Timer for the MicroBit"""
from microbit import display, accelerometer, sleep, button_a, button_b, running_time, Image
import radio

# A Staky Start Talk Time

SHAKY_ID = 'asstt'


def start_up_screen():
"""Display the start up screen"""
display.show(Image.ALL_CLOCKS, delay=100, loop=False, clear=True)
return


def show_power_on():
"""Display power on configuration"""
display.set_pixel(0, 0, 9)
return


def clear_message_buffer():
"""Wait until radio buffer is clear"""
while radio.receive() is not None:
pass
return


def wait_till_shaking_stops():
"""Wait until shaking stops"""
while accelerometer.current_gesture() == 'shake':
pass
return


def get_ready_to_go_again():
"""Reset Timer"""
clear_message_buffer()
wait_till_shaking_stops()
return


def count_down(delay):
"""Count down and show progress"""
on_image = Image('99999:99999:99999:99999:99999')
display.show(on_image)

for y_coord in range(5):
for x_coord in range(5):
wait = delay
while wait >= 300:
sleep(300)
wait -= 300
if abandon_talk() is True:
return

# Flash the last row, so making it clear that
# the talk is coming to an end

if y_coord == 4:
for i in range(x_coord, 5):
brightness = display.get_pixel(i, y_coord)
if brightness == 0:
brightness = 9
else:
brightness = 0
display.set_pixel(i, y_coord, brightness)

sleep(wait)
display.set_pixel(x_coord, y_coord, 0)

start_up_screen()
return


def display_minutes(minutes):
"""Show minutes"""
i = 0
for y_coord in range(5):
for x_coord in range(5):
i += 1
if i <= minutes:
display.set_pixel(x_coord, y_coord, 9)
else:
if x_coord == 0 and y_coord == 0 and minutes < 1:
display.set_pixel(x_coord, y_coord, 4)
else:
display.set_pixel(x_coord, y_coord, 0)


def get_talk_time(minutes):
"""Setup talk time"""
display.scroll('A -1, B +1')

# clear press counters

button_a.get_presses()
button_b.get_presses()

quit_flag = False

while quit_flag is not True:
minutes = minutes - button_a.get_presses() \
+ button_b.get_presses()
display_minutes(int(minutes))

# To exit press a for 2 seconds

if button_a.is_pressed():
start = running_time()

while button_a.is_pressed():
if running_time() - start > 2000:
quit_flag = True
display.scroll(str(int(minutes)))

return minutes


def minutes_to_delay(minutes):
"""Compute delay from minutes"""
return minutes * 60 * 1000 / 25


def delay_to_minutes(delay):
"""Compute minutes from delay"""
return delay * 25 / (60 * 1000)


def message_to_delay(receivedmess):
"""Get delay from radio"""
if receivedmess is not None:
(asstdev, started, remotetime) = receivedmess.split()

if asstdev == SHAKY_ID and started == 'start':
return float(remotetime)

return -1


def abandon_talk():
"""Abandon talk"""
if button_a.is_pressed():
radio.send(SHAKY_ID + ' ' + 'stop')
display.show(Image.SKULL)
while button_a.is_pressed():
pass
return True

receivedmess = radio.receive()
if receivedmess is not None:
try:
(asstdev, stopped) = receivedmess.split()
except ValueError:
return False

if asstdev == SHAKY_ID and stopped == 'stop':
return True

return False


def main():
"""Main function for the timer"""

# set the number minutes that your talk is to last for.
minutes = 1

# convert to the delay needed to turn off each LED
delay = minutes_to_delay(minutes)

start_up_screen()
show_power_on()

radio.on()

while True:

received_message = radio.receive()

delay_from_remote = message_to_delay(received_message)

if delay_from_remote >= 0:
delay = delay_from_remote
count_down(delay)
get_ready_to_go_again()

# Show number of mins

display_minutes(delay_to_minutes(delay))

# To enter demo mode press button a for > 2 secs

if button_b.is_pressed():
start = running_time()

while button_b.is_pressed():
pass

if running_time() - start > 2000:
delay = minutes_to_delay(15 / 60)
display.scroll('Talk 15 secs')

if button_a.is_pressed():
delay = minutes_to_delay(get_talk_time(delay_to_minutes(delay)))
start_up_screen()
display_minutes(delay_to_minutes(delay))

if accelerometer.current_gesture() == 'shake':
send_message = True
while accelerometer.current_gesture() == 'shake':
delay_from_remote = message_to_delay(received_message)
if delay_from_remote >= 0:
delay = delay_from_remote
send_message = False

if send_message:
radio.send(SHAKY_ID + ' ' + 'start ' + str(delay))

count_down(delay)
get_ready_to_go_again()


if __name__ == "__main__":
main()
11 changes: 11 additions & 0 deletions BBC-Micro-Bit/Compass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from microbit import *


# Start calibrating
compass.calibrate()

# Try to keep the needle pointed in (roughly) the correct direction
while True:
sleep(100)
needle = ((15 - compass.heading()) // 30) % 12
display.show(Image.ALL_CLOCKS[needle])
58 changes: 58 additions & 0 deletions BBC-Micro-Bit/Die Roller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from microbit import *
import random


dienum6 = ["1", "2", "3", "4", "5", "6",]
dienum10 = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0",]
dienum20 = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12",
"13", "14", "15", "16", "17", "18", "19", "20",]

die61 = Image("00000:00000:00900:00000:00000")
die62 = Image("90000:00000:00000:00000:00009")
die63 = Image("90000:00000:00900:00000:00009")
die64 = Image("90009:00000:00000:00000:90009")
die65 = Image("90009:00000:00900:00000:90009")
die66 = Image("90009:00000:90009:00000:90009")
die6nums = [die61, die62, die63, die64, die65, die66,]
display.show(Image.ARROW_W)
sleep(200)
display.scroll("d6")
display.show(Image.ARROW_W)
sleep(200)
display.scroll("d6")
sleep(1000)
display.show(Image.ARROW_E)
sleep(200)
display.scroll("d10")
display.show(Image.ARROW_E)
display.scroll("d10")
sleep(1000)
display.show(Image.ARROW_W)
sleep(200)
display.show(Image.ARROW_E)
sleep(200)
display.scroll("d20")
display.show(Image.ARROW_W)
sleep(200)
display.show(Image.ARROW_E)
sleep(200)
display.scroll("d20")
sleep(1000)

while True:
sleep(2000)
x = button_a.get_presses()
y = button_b.get_presses()
if x==1 and y==1:
outnumber3 = random.choice(dienum20)
display.scroll("d20")
display.show(outnumber3, delay=700)
elif x==1:
outnumber = random.choice(die6nums)
display.scroll("d6")
display.show(outnumber)
elif y==1:
outnumber2 = random.choice(dienum10)
display.scroll("d10")
display.show(outnumber2, delay=700)

Loading

0 comments on commit 538d07b

Please sign in to comment.