started working on controlling freq + the lil control panel

This commit is contained in:
PiFestim 2022-07-29 03:57:38 +01:00
parent 2b086083cd
commit d50b67fed1

64
rotary.py Normal file
View File

@ -0,0 +1,64 @@
import time
from pigpio_encoder.rotary import Rotary
bands = {
"80m":[3.5, 4],
"40m":[7, 7.3],
"20m":[14, 14.35],
"10m":[28, 29.7],
"2m":[144,146],
"70cm":[430,440]
}
band = iter(bands)
CURRENT_BAND = None
def setup_encoder(ranges:list):
def rotary_callback(counter):
print("Counter value: ", round(counter, 2))
my_rotary = Rotary(
clk_gpio=17,
dt_gpio=27,
sw_gpio=22
)
my_rotary.setup_rotary(
min=ranges[0],
max=ranges[1],
scale=.25,
debounce=300,
rotary_callback=rotary_callback
)
#my_rotary.watch()
return my_rotary
def change_band(plus:bool=False, minus:bool=False):
global CURRENT_BAND
if plus:
CURRENT_BAND = next(band)
if minus:
try:
CURRENT_BAND = bands[list(bands.keys)[list(bands.keys()).index(CURRENT_BAND)-1]]
print(CURRENT_BAND)
except Exception as e:
print(e)
encoder = setup_encoder(bands[CURRENT_BAND])
print(CURRENT_BAND)
return encoder
encoder = setup_encoder(bands[next(band)])
def main():
global encoder
while True:
if encoder.counter >= encoder.max:
encoder = change_band(plus=True)
if encoder.counter <= encoder.min:
encoder = change_band(minus=True)
time.sleep(.5)
if __name__ == "__main__":
main()