so I've set up a potentiometer and an LED and a section of the code is below:
while True:
if (GPIO.input(22) == GPIO.HIGH):
now = str(datetime.now())
text_file = open("button.txt", "w")
text_file.write("\n switch activated at " + now)
text_file.close()
print("switch activated at" + now)
while GPIO.input(22) == GPIO.HIGH:
GPIO.output(4, GPIO.HIGH)
else:
GPIO.output(4, GPIO.LOW)
IT works well, and the LED turns on when the pot is activated and turns off when it's deactivated. Except it only saves the time for the last that the potentiometer is activated, can i do anything to fix this? This is my first time trying to save things to a .txt file so please be lenient.