-
Notifications
You must be signed in to change notification settings - Fork 0
/
cube.py
207 lines (166 loc) · 6.95 KB
/
cube.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/usr/bin/python
import smbus # Εισαγωγή βιβλιοθήκης για την εισαγωγή ήχου
import math # Εισαγωγή βιβλιοθήκης για μαθηματικές σχέσεις
import web # Εισαγωγή βιβλιοθήκης για Ιντερνετ
import socket # Εισαγωγή βιβλιοθήκης για read(), write() επιλογές
import sys # Εισαγωγή βιβλιοθήκης για παραμέτρους συστήματος
import os # Εισαγωγή βιβλιοθήκης για κλήση εντολών στο λειτουργικό σύστημα
#Date and time module
import time # Εισαγωγή βιβλιοθήκης για έξοδο στοιχείων χρόνου
#Music import
from pygame import mixer # Εισαγωγή βιβλιοθήκης για αναπαραγωγής μουσικής
# Power management registers
power_mgmt_1 = 0x6b
power_mgmt_2 = 0x6c
gyro_scale = 131.0
accel_scale = 16384.0
address = 0x68 # This is the address value read via the i2cdetect command
bus = smbus.SMBus(1) # or bus = smbus.SMBus(1) for Revision 2 boards
# Συνάρτηση αξιοποίησης δεδομένων από αισθητήρα
def read_all():
raw_gyro_data = bus.read_i2c_block_data(address, 0x43, 6)
raw_accel_data = bus.read_i2c_block_data(address, 0x3b, 6)
gyro_scaled_x = twos_compliment((raw_gyro_data[0] << 8) + raw_gyro_data[1]) / gyro_scale
gyro_scaled_y = twos_compliment((raw_gyro_data[2] << 8) + raw_gyro_data[3]) / gyro_scale
gyro_scaled_z = twos_compliment((raw_gyro_data[4] << 8) + raw_gyro_data[5]) / gyro_scale
accel_scaled_x = twos_compliment((raw_accel_data[0] << 8) + raw_accel_data[1]) / accel_scale
accel_scaled_y = twos_compliment((raw_accel_data[2] << 8) + raw_accel_data[3]) / accel_scale
accel_scaled_z = twos_compliment((raw_accel_data[4] << 8) + raw_accel_data[5]) / accel_scale
return (gyro_scaled_x, gyro_scaled_y, gyro_scaled_z, accel_scaled_x, accel_scaled_y, accel_scaled_z)
def twos_compliment(val):
if (val >= 0x8000):
return -((65535 - val) + 1)
else:
return val
# Συνάρτηση μέτρησης απόστασης
def dist(a, b):
return math.sqrt((a * a) + (b * b))
# Συνάρτηση κατακόρυφης περιστροφής
def get_y_rotation(x,y,z):
radians = math.atan2(x, dist(y,z))
return math.degrees(radians)
# Συνάρτηση οριζόντιας περιστροφής
def get_x_rotation(x,y,z):
radians = math.atan2(y, dist(x,z))
return math.degrees(radians)
# Συνάρτηση ηχητικού μηνύματος
def speak(msg):
os.system('espeak " ' + msg +'" --stdout | aplay -D sysdefault:CARD=0');
print(msg);
time.sleep(2);
#Assign week days
week=["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
#Assign classes per day
MonProgram = ['Greek Language', 'Greek Language', 'Computer Science', 'Maths', 'Physics', 'Gymnastics', 'English language'];
TueProgram = ['Greek Language', 'Greek Language', 'Maths', 'History', 'Geography', 'English', 'Music'];
WenProgram = ['Greek Language', 'Greek Language', 'Maths', 'Physics', 'Religion studies', 'French-German language', 'Civil Education'];
ThuProgram = ['Greek Language', 'Greek Language', 'Maths', 'French-German language', 'English language', 'History', 'Gymnastics'];
FriProgram = ['Greek Language', 'Greek Language', 'French-German laguage', 'Geography', 'Relegion studies', 'English language', 'Arts'];
#Assign school break
school_brake=["08:21", "09:44", "10:11", "11:39", "11:56", "12:34", "12:46", "13:24", "13:31", "14:09"]
#Assign day and month
day = time.strftime("%A")
month = time.strftime("%B")
t = time.strftime("%H:%M")
print(str(day), str(month))
print(t)
hour, minute = t.split(":");
print(minute)
#Main
client_socket=BluetoothSocket( RFCOMM )
client_socket.connect(("00:22:43:CD:96:E6", 4))
speak("Hello!");
while (True):
time.sleep(60);
values = read_all()
temp = float(values[0])
speak('Outside temprature is', temp);
day = time.strftime("%A")
month=time.strftime("%B")
t = time.strftime("%H:%M")
print(str(day), str(month))
print(t)
hour, minute = t.split(":");
nowDay = str(day);
nowHour = int(hour);
nowMin = int(minute);
if (nowDay == 'Monday'):
todayProgram = MonProgram;
if (nowDay == 'Tuesday'):
todayProgram = TueProgram;
if (nowDay == 'Wednesday'):
todayProgram = WenProgram;
if (nowDay == 'Thursday'):
todayProgram = ThuProgram;
if (nowDay == 'Friday'):
todayProgram = FriProgram;
if ((nowHour == 8) and (nowMin == 30)):
speak("Good morning! I wish you all a nice week");
speak("Let's remember our program for today");
speak("Today is " + nowDay);
if (nowDay == 'Monday'):
todayProgram = MonProgram;
for course in MonProgram:
speak(course);
if (nowDay == 'Tuesday'):
todayProgram = TueProgram;
for course in TueProgram:
speak(course);
if (nowDay == 'Wednesday'):
todayProgram = WenProgram;
for course in WenProgram:
speak(course);
if (nowDay == 'Thursday'):
todayProgram = ThuProgram;
for course in ThuProgram:
speak(course);
if (nowDay == 'Friday'):
todayProgram = FriProgram;
for course in FriProgram:
speak(course);
mixer.init()
mixer.music.load('/home/pi/Desktop/Sia_Flames.mp3')
mixer.music.play()
#First break
if ((nowHour == 9) and (nowMin == 43)):
speak("Break in one minute");
speak("Next hour, we will be studing " + todayProgram[2]);
if ((nowHour == 9) and (nowMin == 45)):
mixer.init()
mixer.music.load('/home/pi/Desktop/Sia_Flames.mp3')
mixer.music.play()
#Second break
if ((nowHour == 10) and (nowMin == 59)):
speak("Break in one minute");
speak("Next hour, we will be studing " + todayProgram[3]);
if ((nowHour == 11) and (nowMin == 1)):
mixer.init()
mixer.music.load('/home/pi/Desktop/Sia_Flames.mp3')
mixer.music.play()
#Third break
if ((nowHour == 11) and (nowMin == 38)):
speak("Break in one minute");
speak("Next hour, we will be studing " + todayProgram[4]);
if ((nowHour == 11) and (nowMin == 40)):
mixer.init()
mixer.music.load('/home/pi/Desktop/Sia_Flames.mp3')
mixer.music.play()
#Forth break
if ((nowHour == 12) and (nowMin == 33)):
speak("Break in one minute");
speak("Next hour, we will be studing " + todayProgram[5]);
if ((nowHour == 12) and (nowMin == 35)):
mixer.init()
mixer.music.load('/home/pi/Desktop/Sia_Flames.mp3')
mixer.music.play()
#Sixth break
if ((nowHour == 13) and (nowMin == 23)):
speak("Break in one minute");
speak("Next hour, we will be studing " + todayProgram[6]);
if ((nowHour == 13) and (nowMin == 25)):
mixer.init()
mixer.music.load('/home/pi/Desktop/Sia_Flames.mp3')
mixer.music.play()
#Seventh break
if ((nowHour == 14) and (nowMin == 9)):
speak("That's all for today!");