Variable wird nicht übergeben

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
Post Reply
Dieter.Tepe@live.de
Posts: 8
Joined: Thu Apr 01, 2021 11:47 am

Variable wird nicht übergeben

Post by Dieter.Tepe@live.de » Fri Apr 09, 2021 5:05 pm

I think I'm out of the wind somewhere.

Code: Select all

import machine
from machine import Pin
import utime

#here I create a variable
sendung = 0

gesendet = machine.Pin(5)

def int_handler(pin):
    sendung = 1
    #everything is recognized correctly here and transmission is = 1

gesendet.irq(trigger=machine.Pin.IRQ_RISING, handler=int_handler)

while True:
    utime.sleep(1)
    #shipment is no longer 1   ????????
    print(sendung)

    if sendung == 1:
        print(" hallo ")
        sendung = 0


How do I make the variable 'sendung' global so that it can be used everywhere ???

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Variable wird nicht übergeben

Post by Roberthh » Fri Apr 09, 2021 5:11 pm

Add the line

global sendung

Into int_handler() at the top.

Dieter.Tepe@live.de
Posts: 8
Joined: Thu Apr 01, 2021 11:47 am

Re: Variable wird nicht übergeben

Post by Dieter.Tepe@live.de » Fri Apr 09, 2021 5:23 pm

Thank you very much

Post Reply