Printing 0

Page 61

The use of PULL_UP and PULL_DOWN has been reversed.

The correct text is:

The simplest switch input program using an internal pull-up is:

from machine import Pin
import time
pinIn = Pin(22, Pin.IN,Pin.PULL_UP)
pinLED = Pin(25, Pin.OUT)

while True:
    if pinIn.value():
        pinLED.on()
    else:
        pinLED.off()
    time.sleep(0.5)


As the internal pull-up resistor is used, the switch can be connected to the line and ground without any external resistors:

and

If you change PULL_UP to PULL_DOWN, the way the switch is connected becomes:

Page 101

The graph axis labels need to be switched.

 

Page 71

The if statements if edge should be changed to if edge==1 to avoid firing on both the rising and falling edge of the switch. That is, change:

    if s==0:
        if edge:
            s=1
            pinLED1.off()
            pinLED2.on()
            pinLED3.off()
    
    elif s==1:
        if edge:
            s=2
            pinLED1.off()
            pinLED2.off()
            pinLED3.on()
    elif s==2:
        if edge:
            s=0
            pinLED1.on()
            pinLED2.off()
            pinLED3.off()

to read:

    if s==0:
        if edge==1:
            s=1
            pinLED1.off()
            pinLED2.on()
            pinLED3.off()
    
    elif s==1:
        if edge==1:
            s=2
            pinLED1.off()
            pinLED2.off()
            pinLED3.on()
    elif s==2:
        if edge==1:
            s=0
            pinLED1.on()
            pinLED2.off()
            pinLED3.off()

 

Page 97

final sentence of penultimate paragraph:

The PWM output in this configuration mimics the workings of an 8-bit A-to-D converter.

should read:

The PWM output in this configuration mimics the workings of an 8-bit D-to-A converter.

 

Page 145

If you connect a logic analyzer to the three pins involved – 4, 6 and 7, you will see the data transfer:

 change to:

If you connect a logic analyzer to the three GPIO lines involved – 4, 6 and 7, you will see the data transfer:

 i.e change pins to GPIO lines

 

Page 180

RH= -6 + 125 * data16 / 216

change to 

RH= -6 + 125 * data16 / 216

change 216 to 216

 

Page 192

You can use the registers to implement a for loop with up to 32 repeats. The jmp instruction can test the value of a register for zero and auto-decrement it after the test. This means an n repeat for loop can be constructed as:

set x,n
loop: nop
jump x--, loop

Using this you can slow the rate at which the GPIO line is toggled by repeating the nop 32 times. However, even if you use:

set x,n
loop: nop [31]
jump x--, loop

the effective rate of toggling the GPIO line is still too great to see an LED flash. To slow it down even more you need two nested loops.

 

change to

 

You can use the registers to implement a for loop with up to 32 repeats. The jmp instruction can test the value of a register for zero and auto-decrement it after the test. This means an n repeat for loop can be constructed as:

set x,n
loop: nop
jmp x--, loop

Using this you can slow the rate at which the GPIO line is toggled by repeating the nop 32 times. However, even if you use:

set x,n
loop: nop [31]
jmp x--, loop

the effective rate of toggling the GPIO line is still too great to see an LED flash. To slow it down even more you need two nested loops.

i.e. change jump to jmp