Likely I am missing something simple.
I have been playing around with a bit of code to exercise an old piece of hardware that I have here. Nothing too fancy, but I am getting an error that currently has me stumped.
My code 'test3.py' currently:
Code: Select all
#!/usr/bin/env micropython
from machine import Pin, I2C
import mcp23017
import machine
import sys
import utime
i2c = I2C(scl=Pin(22), sda=Pin(21))
mcp = mcp23017.MCP23017(i2c, 0x20)
BlueLed = Pin(16,Pin.OUT)
BlueLed.value(1)
repl_button = machine.Pin(0, machine.Pin.IN, machine.Pin.PULL_UP)
x=0
# list interface
mcp[0].output(0)
mcp[1].output(0)
mcp[2].output(0)
mcp[3].output(0)
mcp[4].output(0)
mcp[5].output(0)
mcp[6].output(0)
mcp[7].output(0)
mcp[8].input(pull=1)
mcp[9].input(pull=1)
mcp[10].input(pull=1)
mcp[11].input(pull=1)
mcp[12].input(pull=1)
mcp[13].input(pull=1)
mcp[14].input(pull=1)
mcp[15].input(pull=1)
while True:
# If button 0 is pressed, drop to REPL
if repl_button.value() == 0:
mcp.porta.gpio = 0
#Line 44 follows next
BlueLed.value(0)
print("Dropping to REPL")
sys.exit()
# Turn LED on and then off
mcp.porta.gpio = x
#print(mcp.porta.gpio)
utime.sleep_ms(500)
BlueLed = not BlueLed
x +=1
Looks to me like a variable scope issue yet, I am unaware of loops posing a such a dilemma, and I can't find anything documenting variable scope specs for within while loops.MicroPython v1.12-87-g96716b46e on 2020-01-26; ESP32 module with ESP32
Type "help()" for more information.
>>>
>>> import test3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "test3.py", line 44, in <module>
AttributeError: 'bool' object has no attribute 'value'
Yes, I know my code is all a bit rough around the edges, but it was never intended to be ready for prime time. This is really just an ongoing experiment and its really just this error I am seeking an assist with, thanks.
Your thoughts would be appreciated.
Cheers,
Brian H.