<commit_before>import RPi.GPIO as GPIO
import time

# tell GPIO to use the Pi's board numbering for pins
GPIO.setmode(GPIO.BOARD)

redLedPin = 22
switchPin = 18
ledOn = False
prevSwitchPressed = False

# set data direction of LED pin to output
GPIO.setup(redLedPin, GPIO.OUT)
GPIO.setup (switchPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)



def loop():
    global prevSwitchPressed
    global ledOn
    curSwitchPressed = not GPIO.input(switchPin)

    # do nothing if switch state has not changed    
    if curSwitchPressed == prevSwitchPressed:
        return
        
    prevSwitchPressed = curSwitchPressed
    
    if curSwitchPressed:
        if ledOn:
            GPIO.output(redLedPin, GPIO.LOW)
            ledOn = False
        else:
            GPIO.output(redLedPin, GPIO.HIGH)
            ledOn = True
    
    return

#loop until keyboard interrupt
try:
    while True:
        loop()
except KeyboardInterrupt:
    pass
    
GPIO.cleanup()<commit_msg>refactored to a toggler class, testing<commit_after>import RPi.GPIO as GPIO
import time

# tell GPIO to use the Pi's board numbering for pins
GPIO.setmode(GPIO.BOARD)

redLedPin = 22
switchPin = 18
toggler = new SwitchToggler(switchPin, redLedPin)

# set data direction of LED pin to output

# simple class that toggles the output value of the outputPin (HIGH/LOW)
# by pressing the switch on switchInputPin
#
# to use, instantiate and call the toggle() method in your loop
class SwitchToggler:
    prevSwitchPressed = False
    outputPinOn = False
    def __init__(self, switchInputPin, outputPin):
        self.switchInputPin = switchInputPin
        self.outputPin = outputPin
        GPIO.setup (switchInputPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        GPIO.setup(outputPin, GPIO.OUT)
    
    def toggle():
        curSwitchPressed = not GPIO.input(self.switchInputPin)
        
        # do nothing if switch state has not changed    
        if curSwitchPressed == prevSwitchPressed:
            return
            
        self.prevSwitchPressed = curSwitchPressed
        
        if curSwitchPressed:
            if self.outputPinOn:
                GPIO.output(self.outputPin, GPIO.LOW)
                self.outputPinOn = False
            else:
                GPIO.output(self.outputPin, GPIO.HIGH)
                self.outputPinOn = True
                
        return
       
    

def loop():
    global toggler
    toggler.toggle()
    
    return

#loop until keyboard interrupt
try:
    while True:
        loop()
except KeyboardInterrupt:
    pass
    
GPIO.cleanup()
{'fraction_non_alphanumeric': 0.06502154328241284, 'fraction_numerical': 0.003133568350959655, 'mean_word_length': 2.360526315789474, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2956043', 'n_tokens_mistral': 765, 'n_tokens_neox': 751, 'n_words': 224}