Quantcast
Viewing all articles
Browse latest Browse all 1288

Python • Re: +/- Value

Hi, I'm trying to add add a +/-1 dead band to a value so the output doesn't chatter with noise. Any help would be greatly appreciated. Thanks

potvalue == (+/-1)+15:


current working code

Code:

#15 Deg        if select15.value() == 0 and potvalue == 15:        relayPin1.value(0)        relayPin2.value(0)        if select15.value() == 0 and potvalue > 15:        relayPin2.value(0)        relayPin1.value(1)        print ("raise")        if select15.value() == 0 and potvalue < 15:        relayPin1.value(0)        relayPin2.value(1)        print ("lower")


I don't think Python has any built-in 'fuzzy arithmetic'.

Something like this might be adaptable to your needs?

Code:

from random import randintfrom time import sleepset_point = 15dead_band = 1upper_limit = set_point + dead_bandlower_limit = set_point - dead_banddef decrease():    print('Too high. Lowering.. ')    def increase():    print('Too low. Raising.. ')    def deactivate():    print('Within range. Deactivated.. ')    for _i in range(10):    current_value = randint(12,18)    print(f'Current reading is {current_value}')    if current_value > upper_limit:        decrease()    elif current_value < lower_limit:        increase()# so current value must be within range -    else:        deactivate()    sleep(2)



[OT:] 5 - Nil !! Back of the net... ! (LCFC only managed 4 - Nil.)

Statistics: Posted by B.Goode — Wed Aug 28, 2024 10:40 am



Viewing all articles
Browse latest Browse all 1288

Trending Articles