-
Notifications
You must be signed in to change notification settings - Fork 0
/
ledlamp.py
127 lines (94 loc) · 2.64 KB
/
ledlamp.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
#!/usr/bin/env python
from rgbmatrix import RGBMatrix
import telegram
import logging
import time
red = 10
green = 0
blue = 0
max=100
step=5
myMatrix = 0
menu_keyboard = telegram.ReplyKeyboardMarkup([['OFF','ON',"000"],['R-','R+','G-','G+','B-','B+']])
menu_keyboard.one_time_keyboard=False
menu_keyboard.resize_keyboard=False
# Enable logging
logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
logger = logging.getLogger(__name__)
def error(bot, update, error):
logger.warn('Update "%s" caused error "%s"' % (update, error))
def cmd_start(bot, update):
bot.sendMessage(update.message.chat_id, text="Hi %s ! I'm LedLampBot.\n" % ( update.message.from_user.first_name), reply_markup=menu_keyboard)
def echo(bot, update):
global red
global green
global blue
print " Testo : [" + update.message.text + "]"
if update.message.text=="ON":
if red==0 and green==0 and blue==0:
red=step
green=step
blue=step
myMatrix.Fill(red, green, blue)
if update.message.text=="OFF":
myMatrix.Clear()
if update.message.text=="000":
red=0
green=0
blue=0
myMatrix.Clear()
if update.message.text=="R+":
if red<=max:
red+=step
myMatrix.Fill(red, green, blue)
if update.message.text=="R-":
if red>=step:
red-=step
myMatrix.Fill(red, green, blue)
if update.message.text=="G+":
if green<=max:
green+=step
myMatrix.Fill(red, green, blue)
if update.message.text=="G-":
if green>=step:
green-=step
myMatrix.Fill(red, green, blue)
if update.message.text=="B+":
if blue<=max:
blue+=step
myMatrix.Fill(red, green, blue)
if update.message.text=="B-":
if blue>=step:
blue-=step
myMatrix.Fill(red, green, blue)
def main():
global update_queue
global myMatrix
rows = 32
chains = 4
parallel = 1
# @LedlampBot
updater = telegram.Updater("194376022:AAHLWzfrLediKJwE3CXk1vYhRwVVBpmRJLQ")
# Get the dispatcher to register handlers
dp = updater.dispatcher
# Definisce gli handler di gestione dei comandi
dp.addTelegramCommandHandler("start", cmd_start)
# on noncommand i.e message - echo the message on Telegram
dp.addTelegramMessageHandler(echo)
# log all errors
dp.addErrorHandler(error)
# Start the Bot
update_queue = updater.start_polling()
myMatrix = RGBMatrix(rows, chains, parallel)
myMatrix.Fill(0, 0, 0)
try:
# Run the bot until the you presses Ctrl-C or the process receives SIGINT,
# SIGTERM or SIGABRT. This should be used most of the time, since
# start_polling() is non-blocking and will stop the bot gracefully.
updater.idle()
except KeyboardInterrupt:
print "Exit"
if __name__ == '__main__':
main()