I am recording voltage readings vs time. I want voltages below 10 into logfile1.txt and voltages above 10 into a second file, logfile2.txt. The following script writes the voltages below 10 into logfile1.txt okay but nothing into logfile2.txt for voltages above 10. The bottom section of my script is ignored. How can I get readings into the second log file?
import sys, time, signal
from time import time, sleep
from Adafruit_ADS1x15 import ADS1x15
ADS1115 =0x01
adc = ADS1x15(ic=ADS1115)
while True:
with open('logfile1.txt', 'w') as f:
while True:
volts = adc.readADCDifferential01(256, 8)
print volts
sleep(1)
if volts < 10:
print >> f, time(), (volts)
with open('logfile2.txt', 'w') as f:
while True:
volts = adc.readADCDifferential01(256, 8)
print volts
sleep(1)
if volts > 10:
print >> f, time(), (volts)