Commit b9c8485071b159390d69833f38e0d67b091ccd55

Authored by Raymond Bakke Pedersen
1 parent 326d4e7b

Kan skrive til fil, ikke konvertert

Showing 1 changed file with 27 additions and 6 deletions   Show diff stats
serialrx
1 1 import serial
  2 +import RPi.GPIO as GPIO
  3 +import time
  4 +
  5 +out_a = 16
  6 +out_b = 12
  7 +in_a = 20
  8 +in_b = 21
  9 +
  10 +GPIO.setwarnings(False)
  11 +GPIO.setmode(GPIO.BCM)
  12 +
  13 +GPIO.setup(out_a, GPIO.OUT, initial = 0)
  14 +GPIO.setup(out_b, GPIO.OUT, initial = 0)
  15 +
  16 +GPIO.setup(in_a, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  17 +GPIO.setup(in_b, GPIO.IN, pull_up_down=GPIO.PUD_UP)
2 18  
3 19 ser = serial.Serial("/dev/ttyS0")
4 20  
5 21 while(1):
6 22 d_in=ser.readline().decode('ascii')
7 23 d_in = d_in.split(',')
8   -# if d_in.find("exit")>-1:#Chat
9   -# print ("program terminated")
10   -# break
11   -# else:
12   -# print("Mottok: "+d_in)
13 24  
14 25 if d_in[0]==("$GPRMC"):#GPS
15   - print(d_in)
  26 + if d_in[2]=='A':
  27 + print(d_in)
  28 +
  29 + if GPIO.input(in_a):
  30 + f = open ('pos','a')
  31 + tilfil = d_in[3]+'\t'+d_in[5]+'\n'
  32 + f.write(tilfil)
  33 + f.close()
  34 + print("Location saved!")
  35 + else:
  36 + print("ERROR: Data is invalid")
16 37  
17 38 ser.close()
... ...