环境:cisco packet tracer8.2.1
想实验:读取的值写入文本文件中
结果:无法写入
from gpio import *
from time import *
from physical import *
from environment import *
from file import *
from os import *
from os.path import * #文件的判断位置
import math
def main():
while True:
t1=analogRead(1)
print(exists("t1.txt"))
t_1=(t1-0)*200/(1023-0)-100+0.5
t2=analogRead(2)
t_2=(t2-0)*200/(1023-0)-100+0.5
print(t_1)
print(t_2)
customWrite(0,str(t_1)+"\n"+str(t_2))
file=open("t1.txt", "aw")
file.write("-")
file.write(str(t_1) + "\n" + str(t_2))
file.close()
delay(5000)
if __name__ == "__main__":
main()