Skip to content

Commit

Permalink
Cleaning up Time with Circuitpython
Browse files Browse the repository at this point in the history
And re-organising the tutorial menu
  • Loading branch information
idstudiolab committed May 13, 2024
1 parent cd02e28 commit c06185b
Show file tree
Hide file tree
Showing 17 changed files with 11 additions and 69 deletions.
60 changes: 1 addition & 59 deletions tutorials/01-time/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,63 +5,7 @@ has_children: false
parent: "Tutorials"
---

# Dealing with Time in Circuit Python - Coding Seminar

# **Modules and Libraries in Circuit Python**

*****************For more information on Modules and Libraries also see the [FAQ section](https://www.notion.so/FAQ-4d1e68a1814b4fd890f08981efcf8a1b) on this page.*

- Modules and libraries are handled quite similarly in many ways. A library will often (maybe always?) be a collection of modules.
- Some **Libraries** also come bundled with the (Circuit)Python installation, and you can see what's on your ItsyBitsy by exploring the file structure.
- If you need to add a **Library** that you don't already have, it's a fairly simple case of downloading it and then copying it to the correct place in the ItsyBitsy file structure. Check the **reference documentation** if you need more help on doing this.
- In order to **use** a **Module** (even a Core Module) or a **Library** that has been installed on your device, you still need to "add it" in each session. This can be done in the (Circuit)Python Console, if you're working there, or in the .py file if you're writing one. This is done using the **import** command. (See example below)

```jsx
import time
```


## The Import Command

*****************For more information on Modules and Libraries also see the [FAQ section](https://www.notion.so/FAQ-4d1e68a1814b4fd890f08981efcf8a1b) on this page.*

- The basic way of doing this is to simply write "**import module_name**" or "**import library_name**" (note that you do this with no file extension, so no ".py" on the name)
- Some modules have pretty long names, and generally in order to use any of the functionality you have to type the name (among other things...). For this reason, there's an option to "**import long_module_name as short_name**" or "**import long_library_name as short_name**".
So instead of:
```jsx
import digitalio
button = digitalio.DigitalInOut(board.D13)
```
You can write:
```python
import digitalio as dig
#Now you can refer to ‘digitalio’ with just ‘dig’
button = dig.DigitalInOut(board.D13)
```
- There is also the option to import only certain functions, constants etc. from a module or library. This is done using the "**from module import function"** syntax e.g. "**from math import sin**". One of the main benefits of doing this is also short-hand. If you import the whole math module, then to use sin you have to write "**math.sin(something)**". If you use the "from" approach above, then you can just do "**sin(something)**"
```jsx
import usb_hid
from adafruit_hid.keyboard import Keyboard
```
## **Finding out what’s in a Module or Library**
*****************For more information on Modules and Libraries also see the FAQ section on this page.*****************
- While you would often want to check documentation online, it can sometimes be quite useful to interrogate the functionality offered by a module or library from within (Circuit)Python.
- This can be done from the (Circuit)Python console. First you import the thing you want to use e.g. "**import math**", then you have two options:
- Typing "**dir(math)**" will simply give you a list of the functions and values 'inside' it
- Typing "**help(math)**" will give you a much longer answer, that actually describes all the functions and values and what they do.
- As a compromise, you also have the option to see the list of things using "**dir()**", and then find out a bit more about it by using "help()". For example, you could write "**help(math.sin)**" to find out about the sin function specifically.
# Dealing with Time in Circuit Python

# **Time in Circuit Python**

Expand Down Expand Up @@ -338,5 +282,3 @@ while True:
# Set the LED state according to the value of LEDstate.
led.value = LEDstate
```

[FAQ](https://www.notion.so/FAQ-4d1e68a1814b4fd890f08981efcf8a1b)
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
layout: default
title: "01 Pomodoro"
title: "02 Pomodoro"
has_children: true
parent: "Tutorials"
---

# 01 Pomodoro Timer
# 02 Pomodoro Timer

In this tutorial, you will learn how to build a Pomodoro Timer. The Pomodoro Technique is a time management technique that allows you to take regular breaks when working on a task. We will use CircuitPython as programming language, and use Mu Editor as our programming environment.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: default
title: "Step 1: Preparation"
parent: "01 Pomodoro"
parent: "02 Pomodoro"
grand_parent: "Tutorials"
---

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: default
title: "Step 2: Setting up the states"
parent: "01 Pomodoro"
parent: "02 Pomodoro"
grand_parent: "Tutorials"
---

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: default
title: "Step 3: Adding the LED"
parent: "01 Pomodoro"
parent: "02 Pomodoro"
grand_parent: "Tutorials"

---
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: default
title: "Step 4: Creating a timer"
parent: "01 Pomodoro"
parent: "02 Pomodoro"
grand_parent: "Tutorials"

---
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: default
title: "Step 5: Adding an alarm"
parent: "01 Pomodoro"
parent: "02 Pomodoro"
grand_parent: "Tutorials"

---
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: default
title: "Step 6: Adding the breaks"
parent: "01 Pomodoro"
parent: "02 Pomodoro"
grand_parent: "Tutorials"

---
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: default
title: "Step 7: Additional visualization using the servo"
parent: "01 Pomodoro"
parent: "02 Pomodoro"
grand_parent: "Tutorials"

---
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: default
title: Step 8 Assembling the embodiment
parent: "01 Pomodoro"
parent: "02 Pomodoro"
grand_parent: "Tutorials"
---

Expand Down

0 comments on commit c06185b

Please sign in to comment.