On a raspberry Pi 4 i have connected a small remote control. I have the buttons in a case statement. One button is the “Select” button. I want my program to count the times this button is pressed and react according to it. So, 1 time pressed, start this, 2 times pressed start that, etc.
I allready have a problem with the increment of my var, from 1 time pressed to 2 time, with +=1.
Someon willing to help?
Thx in advance, Pit
I add my code so far it is adjusted code found on the internet.
#!/usr/bin/python
import subprocess
import sys
import os
from lirc import RawConnection
def ProcessIRRemote():
#get IR command
#keypress format = (hexcode, repeat_num, command_key, remote_id)
try:
keypress = conn.readline(.0001)
except:
keypress=""
if (keypress != "" and keypress != None):
data = keypress.split()
sequence = data[1]
command = data[2]
#ignore command repeats
if (sequence != "00"):
return
#print(command)
match command:
case "KEY_POWER":
print("De aan en uit knop.")
os.system('systemctl poweroff')
case "KEY_MUTE":
print("Stilte.")
case "KEY_PREVIOUS":
print("Vorige nummer.")
case "KEY_PLAY":
print("Huidige nummer afspelen.")
case "KEY_NEXT":
print("Volgende nummer.")
case "KEY_UP":
print("Wielpijl op.")
case "KEY_LEFT":
print("Wielpijl links.")
case "KEY_OK":
print("Wielpijl OK.")
case "KEY_RIGHT":
print("Wielpijl rechts.")
case "KEY_DOWN":
print("Wielpijl neer.")
case "KEY_EXIT":
print("De Exit knop.")
case "KEY_CHANNEL":
print("Keuzeknop.")
case "KEY_SELECT":
gedrukt += 1
print(gedrukt)
case "KEY_VOLUMEDOWN":
print("Geluid zachter.")
case "KEY_VOLUMEUP":
print("Geluid harder.")
#define Global
conn = RawConnection()
global gedrukt
gedrukt = 0
print("Starting Up...")
while True:
ProcessIRRemote()