Mercurial > d1workshop
changeset 51:9b344c729142
Remove all mentions of .low(), .high() and .value()
Because they were removed in recent versions of MicroPython.
Also add a note about ampy.
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Fri, 07 Jul 2017 19:38:07 +0200 |
| parents | 6482082f9187 |
| children | 65374c79d8ff |
| files | basics.rst |
| diffstat | 1 files changed, 40 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/basics.rst Fri Jul 07 18:59:34 2017 +0200 +++ b/basics.rst Fri Jul 07 19:38:07 2017 +0200 @@ -18,7 +18,7 @@ from machine import Pin led = Pin(2, Pin.OUT) - led.low() + led(0) The first line "imports" the "Pin" function from the "machine" module. In Python, to use any libraries, you first have to import them. The "machine" @@ -29,32 +29,32 @@ telling it to switch it into output mode. Once created, the pin is assigned to the variable we called "led". -Finally, we bring the pin low, by calling the "low" method on the "led" -variable. At this point the LED should start shining. In fact, it may have -started shining a line earlier, because once we switched the pin into output -mode, its default state is "low". +Finally, we bring the pin low, by calling the "led" variable with value 0. At +this point the LED should start shining. In fact, it may have started shining a +line earlier, because once we switched the pin into output mode, its default +state is "low". Now, how to make the LED stop shining? There are two ways. We could switch it back into "input" mode, where the pin is not connected to anything. Or we could bring it "high". If we do that, both ends of the LED will be connected to "plus", and the current won't flow. We do that with:: - led.high() + led(1) -Now, how can we make the LED blink 10 times? We could of course type -``led.low()`` and ``led.high()`` ten times quickly, but that's a lot of work -and we have computers to do that for us. We can repeat a command or a set of -commands using the "for" loop:: +Now, how can we make the LED blink 10 times? We could of course type ``led(0)`` +and ``led(1)`` ten times quickly, but that's a lot of work and we have +computers to do that for us. We can repeat a command or a set of commands using +the "for" loop:: for i in range(10): - led.high() - led.low() + led(1) + led(0) Note, that when you are typing this, it will look more like:: >>> for i in range(10): - ... led.high() - ... led.low() + ... led(1) + ... led(0) ... ... >>> @@ -75,9 +75,9 @@ And then we will repeat our program, but with the waiting included:: for i in range(10): - led.high() + led(1) time.sleep(0.5) - led.low() + led(0) time.sleep(0.5) Now the LED should turn on and off every half second. @@ -111,9 +111,9 @@ led = Pin(14, Pin.OUT) for i in range(10): - led.high() + led(1) time.sleep_ms(500) - led.low() + led(0) time.sleep_ms(500) Again, you should see the LED blink 10 times, half a second for each blink. @@ -189,9 +189,9 @@ led = Pin(2, Pin.OUT) button = Pin(14, Pin.IN, Pin.PULL_UP) while True: - if not button.value(): - led.value(not led.value()) - while not button.value(): + if not button(): + led(not led()) + while not button(): pass We have used ``Pin.IN`` because we want to use ``gpio14`` as an input pin, on @@ -222,9 +222,9 @@ button = Pin(14, Pin.IN, Pin.PULL_UP) while True: if not button.value(): - led.value(not led.value()) + led(not led()) time.sleep_ms(300) - while not button.value(): + while not button(): pass Here we wait 3/10 of a second -- too fast for a human to notice, but enough for @@ -394,7 +394,7 @@ to open it in the browser. In order to connect to your board, you have to know its address. If the board -works in accesspoint mode, it uses the default address. If it's connected to +works in access point mode, it uses the default address. If it's connected to WiFi, you can check it with this code:: import network @@ -463,6 +463,22 @@ .. note:: You have to have Python installed on your computer for this to work. +This requires you to setup a network connection on your board first. However, +you can also upload files to your board using the same serial connection that +you use for the interactive console. You just need to install a small utility +program:: + + pip install adafruit-ampy + +And then you can use it to copy files to your board:: + + ampy --port=/dev/ttyUSB0 put yourfile.xxx + +.. warning:: + The serial connection can be only used by a single program at a time. + Make sure that your console is discobbected while you use ampy, otherwise + you may get a cryptic error about it not having the access rights. + HTTP Requests =============
