changeset 1:e558443c8d16

Add section on external LED
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Wed, 08 Jun 2016 23:15:22 +0200
parents 5050298bb041
children 94a51485a7e6
files external.rst index.rst
diffstat 2 files changed, 38 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/external.rst	Wed Jun 08 23:15:22 2016 +0200
@@ -0,0 +1,37 @@
+External Components
+*******************
+
+Now let's try the same, but not with the build-in LED -- let's connect an
+external LED and try to use that. The connection should look like this:
+
+.. image:: ./images/blink.png
+
+Note how one leg of the LED is a little bit longer, and the other had a
+flattening on the plastic of the LED next to it. The long leg should go to the
+plus, and the short one to the minus. We are connecting the LED in opposite way
+than the internal one is connected -- between the pin and ``gnd``. That means
+that it will shine when the pin is high, and be dark when it's low.
+
+Also note how we added a resistor in there. That is necessary to limit the
+amount of current that is going to flow through the LED, and with it, its
+brightness. Without the resistor, the LED would shine very bright for a short
+moment, until either it, or the board, would overheat and break. We don't want
+that.
+
+Now, let's try the code::
+
+    from machine import Pin
+    import time
+
+    led = Pin(14, Pin.OUT)
+    for i in range(10):
+        led.high()
+        time.sleep_ms(500)
+        led.low()
+        time.sleep_ms(500)
+
+Again, you should see the LED blink 10 times, half a second for each blink.
+
+This time we used ``time.sleep_ms()`` instead of ``time.sleep()`` -- it does
+the same thing, but takes the number of milliseconds instead od seconds as the
+parameter, so we don't have to use fractions.
--- a/index.rst	Wed Jun 08 23:02:27 2016 +0200
+++ b/index.rst	Wed Jun 08 23:15:22 2016 +0200
@@ -15,6 +15,7 @@
    board.rst
    connecting.rst
    blink.rst
+   external.rst
 
 
 Indices and tables