Skip to content

Instantly share code, notes, and snippets.

@MizukiSonoko
Created April 19, 2015 04:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MizukiSonoko/887bcf2aa71c4d1e7667 to your computer and use it in GitHub Desktop.
Save MizukiSonoko/887bcf2aa71c4d1e7667 to your computer and use it in GitHub Desktop.
PRINCESS0
const int LED = 13;
int val = 0;
int light = 0;
int count = 0;
bool up = true;
void setup(){
pinMode(12, INPUT);
pinMode(11, INPUT);
pinMode( 6, OUTPUT);
pinMode(LED, OUTPUT);
Serial.begin(9600);
}
void loop(){
val = analogRead(0);
Serial.println(light);
if (val > 200) {
if(light < 255){
if(count > 2){
if(up){
light++;
}else{
light--;
}
count = 0;
}
count++;
}else if(light < 190){
up = true;
} else{
up = false;
}
analogWrite(6, light);
}else {
if(light > 0){
if(count > 2){
if(up){
light++;
}else{
light--;
}
count = 0;
}
count++;
}else if(light > 60){
up = false;
} else{
up = true;
}
analogWrite(6, light);
}
}
#!/usr/bin/python
# -*- coding:utf-8 -*-
import datetime
import pytz
import urllib2
import chardet
import re
import ephem
import math
RANGE = 550000
# Cite https://github.com/moxuse/prismEphem.py/blob/master/prismEphem.py
def readFile():
lines = ['','','']
#print 'file !!!'
tleFile = open('tleData.txt', 'r')
lines = tleFile.readlines()
fileLineNum = len(lines)
for i in range(fileLineNum):
lines[i] = lines[i]
tleFile.close()
return lines
def six2ten(six):
ten = six.split(':')
t0 = float(ten[0])
t1 = float(ten[1])*0.0166666666667
t2 = float(ten[2])*0.000277777777778
if t0>=0:
return str (t0 + t1 + t2)
if t0<0:
return str (-(t0 - t1 - t2))
def get(LAT=0.0,LON=0.0,ALT=0.0,NAME=""):
longtitude = []
latitude = []
elevation = []
line1 = []
line2 = []
line3 = []
#fetch NORAD site
url = 'http://celestrak.com/NORAD/elements/amateur.txt'
url2 = 'http://www.tle.info/data/science.txt'
htmlOpener = urllib2.urlopen(url)
if(htmlOpener.code != 200): exit(0)
src = htmlOpener.read().splitlines()
if len(src) > 0:
count = 0
for line in src:
if len(src) == count + 1:
break
if src[count + 1][0] is str(1):
line1.append(src[count] )
line2.append(src[count+1] )
line3.append(src[count+2] )
print src[count]
count+=1
else:
print "Failed"
quit()
inIN = False
#timezone pref use UTC now
utcTime = datetime.datetime.utcnow()
for i in range(0, len(line1)):
sat = ephem.readtle(line1[i], line2[i], line3[i])
timeNow = utcTime.strftime("%Y/%m/%d %H:%M") #we don't concern in seconds
sat.compute( timeNow )
longtitude = six2ten(str(sat.sublong))
latitude = six2ten(str(sat.sublat))
elevation = sat.elevation
dist = math.pow(float(longtitude) - LON,2) + math.pow(float(latitude) - LAT,2) + math.pow(float(elevation) - ALT,2)
dist = math.sqrt(dist)
if dist < RANGE:
print line1[i]
if NAME in line1[i]:
inIN = True
print "#############"
return inIN
def getlist():
res = []
#fetch NORAD site
url = 'http://celestrak.com/NORAD/elements/amateur.txt'
url2 = 'http://www.tle.info/data/science.txt'
htmlOpener = urllib2.urlopen(url)
if(htmlOpener.code != 200): exit(0)
src = htmlOpener.read().splitlines()
if len(src) > 0:
count = 0
for line in src:
if len(src) == count + 1:
break
if src[count + 1][0] is str(1):
res.append(src[count] )
count+=1
else:
print "Failed"
quit()
return res
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response
import subprocess
import random
from exe import *
def hello_world(request):
lat = float(request.params["lat"])
lon = float(request.params["lon"])
alt = float(request.params["alt"])
name = request.params["name"]
res = get(lat, lon, alt, name)
return Response(str(res))
def list_get(request):
res = getlist()
return Response(str(res))
if __name__ == '__main__':
config = Configurator()
config.add_route('hello', '/hikoseki')
config.add_route('getline', '/ichiran')
config.add_view(hello_world, route_name='hello')
config.add_view(list_get, route_name = 'getline')
app = config.make_wsgi_app()
server = make_server('0.0.0.0', 8080, app)
server.serve_forever()
@MizukiSonoko
Copy link
Author

Source code PRINCESS0's api & arduino.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment