summaryrefslogtreecommitdiffstatshomepage
path: root/docs/tutorial
diff options
context:
space:
mode:
Diffstat (limited to 'docs/tutorial')
-rw-r--r--docs/tutorial/amp_skin.rst1
-rw-r--r--docs/tutorial/fading_led.rst12
-rw-r--r--docs/tutorial/index.rst10
-rw-r--r--docs/tutorial/lcd_skin.rst3
-rw-r--r--docs/tutorial/pass_through.rst17
-rw-r--r--docs/tutorial/power_ctrl.rst13
-rw-r--r--docs/tutorial/repl.rst2
7 files changed, 51 insertions, 7 deletions
diff --git a/docs/tutorial/amp_skin.rst b/docs/tutorial/amp_skin.rst
index 988bcc2bca..66513a5b2a 100644
--- a/docs/tutorial/amp_skin.rst
+++ b/docs/tutorial/amp_skin.rst
@@ -26,6 +26,7 @@ potentiometer, which is an I2C device with address 46 on the ``IC2(1)`` bus.
To set the volume, define the following function::
+ import pyb
def volume(val):
pyb.I2C(1, pyb.I2C.MASTER).mem_write(val, 46, 0)
diff --git a/docs/tutorial/fading_led.rst b/docs/tutorial/fading_led.rst
index 5c92cc33a5..b40af3e3b1 100644
--- a/docs/tutorial/fading_led.rst
+++ b/docs/tutorial/fading_led.rst
@@ -6,7 +6,7 @@ In addition to turning LEDs on and off, it is also possible to control the brigh
.. image:: http://upload.wikimedia.org/wikipedia/commons/a/a9/Fade.gif
Components
-==========
+----------
You will need:
@@ -16,14 +16,14 @@ You will need:
- `Breadboard <http://en.wikipedia.org/wiki/Breadboard>`_ (optional, but makes things easier)
Connecting Things Up
-====================
+--------------------
For this tutorial, we will use the ``X1`` pin. Connect one end of the resistor to ``X1``, and the other end to the **anode** of the LED, which is the longer leg. Connect the **cathode** of the LED to ground.
.. image:: img/fading_leds_breadboard_fritzing.png
Code
-====
+----
By examining the :ref:`quickref`, we see that ``X1`` is connected to channel 1 of timer 5 (``TIM5 CH1``). Therefore we will first create a ``Timer`` object for timer 5, then create a ``TimerChannel`` object for channel 1::
from pyb import Timer
@@ -59,7 +59,7 @@ To achieve the fading effect shown at the beginning of this tutorial, we want to
cur_width = min_width
Breathing Effect
-================
+----------------
If we want to have a breathing effect, where the LED fades from dim to bright then bright to dim, then we simply need to reverse the sign of ``wstep`` when we reach maximum brightness, and reverse it again at minimum brightness. To do this we modify the ``while`` loop to be::
@@ -78,12 +78,12 @@ If we want to have a breathing effect, where the LED fades from dim to bright th
wstep *= -1
Advanced Exercise
-==================
+-----------------
You may have noticed that the LED brightness seems to fade slowly, but increases quickly. This is because our eyes interprets brightness logarithmically (`Weber's Law <http://www.telescope-optics.net/eye_intensity_response.htm>`_
), while the LED's brightness changes linearly, that is by the same amount each time. How do you solve this problem? (Hint: what is the opposite of the logarithmic function?)
Addendum
-========
+--------
We could have also used the digital-to-analog converter (DAC) to achieve the same effect. The PWM method has the advantage that it drives the LED with the same current each time, but for different lengths of time. This allows better control over the brightness, because LEDs do not necessarily exhibit a linear relationship between the driving current and brightness.
diff --git a/docs/tutorial/index.rst b/docs/tutorial/index.rst
index 5d48b611f7..19e48b5cad 100644
--- a/docs/tutorial/index.rst
+++ b/docs/tutorial/index.rst
@@ -22,6 +22,16 @@ the tutorial through in the order below.
usb_mouse.rst
timer.rst
assembler.rst
+ power_ctrl.rst
+
+Tips, tricks and useful things to know
+--------------------------------------
+
+.. toctree::
+ :maxdepth: 1
+ :numbered:
+
+ pass_through.rst
Tutorials requiring extra components
------------------------------------
diff --git a/docs/tutorial/lcd_skin.rst b/docs/tutorial/lcd_skin.rst
index 86f0be0aa9..997c1c6f46 100644
--- a/docs/tutorial/lcd_skin.rst
+++ b/docs/tutorial/lcd_skin.rst
@@ -24,12 +24,14 @@ Using the LCD
To get started using the LCD, try the following at the Micro Python prompt.
Make sure the LCD skin is attached to the pyboard as pictured at the top of this page. ::
+ >>> import pyb
>>> lcd = pyb.LCD('X')
>>> lcd.light(True)
>>> lcd.write('Hello uPy!\n')
You can make a simple animation using the code::
+ import pyb
lcd = pyb.LCD('X')
lcd.light(True)
for x in range(-80, 128):
@@ -46,6 +48,7 @@ MPR121 capacitive touch sensor has address 90.
To get started, try::
+ >>> import pyb
>>> i2c = pyb.I2C(1, pyb.I2C.MASTER)
>>> i2c.mem_write(4, 90, 0x5e)
>>> touch = i2c.mem_read(1, 90, 0)[0]
diff --git a/docs/tutorial/pass_through.rst b/docs/tutorial/pass_through.rst
new file mode 100644
index 0000000000..309ef58e74
--- /dev/null
+++ b/docs/tutorial/pass_through.rst
@@ -0,0 +1,17 @@
+Making a UART - USB pass through
+================================
+
+It's as simple as::
+
+ import pyb
+ import select
+
+ def pass_through(usb, uart):
+ while True:
+ select.select([usb, uart], [], [])
+ if usb.any():
+ uart.write(usb.read(256))
+ if uart.any():
+ usb.write(uart.read(256))
+
+ pass_through(pyb.USB_VCP(), pyb.UART(1, 9600))
diff --git a/docs/tutorial/power_ctrl.rst b/docs/tutorial/power_ctrl.rst
new file mode 100644
index 0000000000..877b7cd7ee
--- /dev/null
+++ b/docs/tutorial/power_ctrl.rst
@@ -0,0 +1,13 @@
+Power control
+=============
+
+:meth:`pyb.wfi` is used to reduce power consumption while waiting for an
+event such as an interrupt. You would use it in the following situation::
+
+ while True:
+ do_some_processing()
+ pyb.wfi()
+
+Control the frequency using :meth:`pyb.freq`::
+
+ pyb.freq(30000000) # set CPU frequency to 30MHz
diff --git a/docs/tutorial/repl.rst b/docs/tutorial/repl.rst
index 51166a0eb9..345a0893ee 100644
--- a/docs/tutorial/repl.rst
+++ b/docs/tutorial/repl.rst
@@ -39,7 +39,7 @@ Open a terminal and run::
screen /dev/tty.usbmodem*
-When you are finishend and want to exit screen, type CTRL-A CTRL-\\.
+When you are finished and want to exit screen, type CTRL-A CTRL-\\.
Linux
-----