Interrupt variable increment problem

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
Posts: 13
Joined: Mon Dec 10, 2018 6:37 am

Interrupt variable increment problem

Post by Nikunj_Vadher » Sat Jan 12, 2019 9:15 am

Code: Select all

import config


def inctmp(p):
  itemp = itemp + 1

def dectmp(p):
  itemp = itemp - 1

p0 = Pin(0, Pin.IN)
p0.irq(trigger=Pin.IRQ_RISING | Pin.IRQ_FALLING, handler=inctmp)

p15 = Pin(15, Pin.IN)
p15.irq(trigger=Pin.IRQ_RISING | Pin.IRQ_FALLING, handler=dectmp)
here file stores 2 variables temp and humidity
whenever try to do hardware interrupt using push button getting following error.

Traceback (most recent call last):
File "<string>", line 24, in inctmp
NameError: local variable referenced before assignment

I am using itemp and ihum in other code.

Posts: 391
Joined: Sat Feb 03, 2018 7:02 pm

Re: Interrupt variable increment problem

Post by kevinkk525 » Sat Jan 12, 2019 11:01 am

That's a basic python problem. I recommend reading tutorials.

The solution however is to do this:

Code: Select all

def inctmp(p):
    global itemp
    itemp = itemp + 1

Post Reply