You are on page 1of 4

Python Coding:

import math
importcmath
importnumpy as np
importcsv
importRPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
#primary usersleds
GPIO.setup(29,GPIO.OUT)
GPIO.setup(31,GPIO.OUT)
GPIO.setup(33,GPIO.OUT)
GPIO.setup(35,GPIO.OUT)
GPIO.setup(37,GPIO.OUT)
#secondary usersleds
GPIO.setup(23,GPIO.OUT)
GPIO.setup(21,GPIO.OUT)
GPIO.setup(19,GPIO.OUT)
GPIO.setup(15,GPIO.OUT)
GPIO.setup(13,GPIO.OUT)
fm=1000
t=np.arange(101)/1
t=t*10**-5
x1=np.cos(np.pi*2*1000*t)
Fc1 = 1000;
Fc2 = 2000;
Fc3 = 3000;
Fc4 = 4000;
Fc5 = 5000;
Fs = 12000;
y1 = np.zeros(len(x1),float);
y2 = np.zeros(len(x1),float);
y3 = np.zeros(len(x1),float);
y4 = np.zeros(len(x1),float);
y5 = np.zeros(len(x1),float);
y = np.zeros(len(x1),float);
def s(x1):
x=np.fft.fft(x1,256)
x_s=(float(1)/(len(x)))*(abs(x))**2
xx=x_s[:129]

return xx
def am(Fc):
tt=np.arange(101)/1
tt=tt*(1/float(Fs))
y=x1*np.cos(2*np.pi*Fc*tt)
return y
f=open('f.csv')
for row in csv.reader(f):
data=row
for i in range(len(x1)):
y[i]=float(data[i])
P=s(y)
tp=0;
chek1 = P[24]*10000;
chek2 = P[45]*10000;
chek3 = P[61]*10000;
chek4 = P[88]*10000;
chek5 = P[104]*10000;
rr=0;
if(chek1 > 8000):
rr=rr+1;
GPIO.output(29,1)
if(chek2 > 8000):
rr=rr+1;
GPIO.output(31,1)
if(chek3 > 8000):
rr=rr+1;
GPIO.output(33,1)
if(chek4 > 8000):
rr=rr+1;
GPIO.output(35,1)
if(chek5 > 8000):
rr=rr+1;
GPIO.output(37,1)
if(rr<3):
forjj in range(2):
if(chek1<8000):
print 'Assigned to User 1 as it was not present.'
GPIO.output(23,1)
y1=am(Fc1)
if(chek2<8000):
print 'Assigned to User 2 as it was not present.'
GPIO.output(21,1)
y2=am(Fc2)
if(chek3<8000):

print 'Assigned to User 3 as it was not present.'


GPIO.output(19,1)
y3=am(Fc3)
if(chek4<8000):
print 'Assigned to User 4 as it was not present. '
GPIO.output(15,1)
y4=am(Fc4)
if(chek5<8000):
print 'Assigned to User 5 as it was not present.'
GPIO.output(13,1)
y5=am(Fc5)
print(' ohhh ')
tp=1
yy = y1 + y2 + y3 + y4 + y5
q=y+yy
P=s(q)
tp=0;
chek1 = P[24]*10000;
chek2 = P[45]*10000;
chek3 = P[61]*10000;
chek4 = P[88]*10000;
chek5 = P[104]*10000;
else:
if(chek1<8000):
print 'Assigned to User 1 as it was not present.'
GPIO.output(23,1)
y1=am(Fc1)
if(chek2<8000):
print 'Assigned to User 2 as it was not present.'
GPIO.output(21,1)
y2=am(Fc2)
if(chek3<8000):
print 'Assigned to User 3 as it was not present.'
GPIO.output(19,1)
y3=am(Fc3)
if(chek4<8000):
print 'Assigned to User 4 as it was not present. '
GPIO.output(15,1)
y4=am(Fc4)
if(chek5<8000):
print 'Assigned to User 5 as it was not present.'
GPIO.output(13,1)
y5=am(Fc5)
#else:

# print 'all user slots are in use'


tp=1
yy = y1 + y2 + y3 + y4 + y5
f = open('ans.csv','w')
a=csv.writer(f)
a.writerow(yy)
f.close()
#GPIO.output(7,1)
#..............slot empty operation......

You might also like