'Missing required positional argument 'input'; GPIOzero Pi interfacing

I have been trying to make a program that would blink 5 leds on my breadboard, and change their speed after a button press, as well as change the brightness based on an output from an ADC chip checking a potentiometer and show both the speed and the brightness on a LCD screen.

Separately, the brightness and the speed functions work, however when I started to try to merge both, I recieved this error:

Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
Speed: 100%
Exception in thread Thread-4:
Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.9/threading.py", line 892, in run
    self.run()
  File "/usr/lib/python3.9/threading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
TypeError: show_pattern() missing 1 required positional argument: 'input'
    self._target(*self._args, **self._kwargs)
TypeError: display2() missing 1 required positional argument: 'input'

Even though I did add the argument in the function declaration, this did not fix the problem. Here is the code:

#!/usr/bin/python3

# Program: LNX255 Assignment 2
# Student: Nikita Ovsov
#    Date: March 2022

from gpiozero import Button, PWMLED
from smbus import SMBus
from math import log10
from signal import pause, signal, SIGTERM, SIGHUP
from time import sleep
from threading import Thread
from rpi_lcd import LCD

delay = 0.1
active = True

leds = (PWMLED(5), PWMLED(6), PWMLED(13), PWMLED(19), PWMLED(26))

bus = SMBus(1)
steps = 255
fade_factor = (steps *log10(2))/(log10(steps))

message = ""

proc = 100

button = Button(18)

lcd = LCD()


def cleanup(signum, frame):
    exit(1)


ads7830_commands = [0x84, 0xc4, 0x94, 0xd4, 0xa4, 0xe4, 0xb4, 0xf4]


def read_ads7830(input):
    bus.write_byte(0x4b, ads7830_commands[input])
    return bus.read_byte(0x4b)


def pos(input):
   values = read_ads7830(input)


def display():
    global message
    global values

    while active:
        message = "Speed: " + '{:1.0f}'.format(proc) + "%"
        print(message)
        sleep(0.25)
        lcd.text(message, 1)


def display2(input):
    global message2
    global values

    while active:
       values = read_ads7830(input)
       message2 = "Brightness: " + '{:1.0f}'.format(values/2.55) + "%"
       print(message)
       sleep(0.25)
       lcd.text(message, 2)


def change_speed():
    global delay
    global proc

    if delay > 0.4:
        delay = 0.1
        proc = 100
    else:
        delay = delay + 0.1
        proc = proc - 20


def show_pattern(input):
    global values
    global fade_factor

    try:
        while active:
            values = read_ads7830(input)
            for num in (0, 1, 2, 3, 4, 3, 2, 1):
                light = (pow(2, (values / fade_factor)) - 1) / steps
                ledxs[num].value = light
                sleep(delay)
                leds[num].value = light

    except AttributeError:
        pass


try:
    signal(SIGTERM, cleanup)
    signal(SIGHUP, cleanup)

    lcd.text("Speed: 100%", 1)

    pos(0)

    button.when_pressed = change_speed

    ptrn = Thread(target=show_pattern, daemon=True)
    ptrn.start()

    display = Thread(target=display, daemon=True)
    display.start()

    display2 = Thread(target=display2, daemon=True)
    display2.start()

    pause()

except KeyboardInterrupt:
    pass

finally:
    active = False
    lcd.clear()
    ptrn.join()
    display.join()
    display2.join()
    sleep(0.25)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source