from m5stack import * from m5stack_ui import * from uiflow import * from ble.ble_central import BLECentral import time screen = M5Screen() screen.clean_screen() screen.set_screen_bg_color(0x015a50) data1 = None name = None central = BLECentral() # Create a Tab view object tabview = lv.tabview(lv.scr_act(), None) # Add 3 tabs (the tabs are page (lv_page) and can be scrolled tab1=tabview.add_tab("Start-/-Stop") tab2=tabview.add_tab("Menu") tab3=tabview.add_tab("RC") # Add content to the tabs label = lv.label(tab1,None) label.set_text("") label = lv.label(tab2,None) label.set_text("") label = lv.label(tab3, None) label.set_text("") label0 = M5Label('Programm ', x=100, y=57, color=0x000, font=FONT_UNICODE_24, parent=tab1) rechts_drehen = M5Btn(text='>', x=172, y=13, w=40, h=40, bg_c=0x000000, text_c=0xffffff, font=FONT_MONT_22, parent=tab1) links_drehen = M5Btn(text='<', x=112, y=13, w=40, h=40, bg_c=0x000000, text_c=0xffffff, font=FONT_MONT_22, parent=tab1) scan_bt = M5Btn(text='Connect', x=113, y=7, w=80, h=40, bg_c=0x000000, text_c=0x02ff00, font=FONT_MONT_14, parent=tab2) an_bt = M5Btn(text='Start', x=262, y=25, w=50, h=50, bg_c=0x000000, text_c=0x18ff00, font=FONT_MONT_14, parent=tab1) aus_bt = M5Btn(text='Stop', x=262, y=81, w=50, h=50, bg_c=0x000000, text_c=0xff0000, font=FONT_MONT_14, parent=tab1) touch_button_disconnect = M5Btn(text='Disconnect', x=7, y=7, w=100, h=40, bg_c=0x000000, text_c=0xff0000, font=FONT_MONT_14, parent=tab2) status_bt_2 = M5Btn(text='Scan', x=200, y=7, w=70, h=40, bg_c=0x010101, text_c=0x00b6a2, font=FONT_MONT_14, parent=tab2) status_label_2 = M5Label('Status', x=137, y=126, color=0x000, font=FONT_UNICODE_24, parent=tab2) checkbox0 = M5Checkbox(text='Dunkelmodus', x=7, y=57, text_c=0x000, check_c=0x0dff00, font=FONT_MONT_14, parent=tab2) geraete_label = M5Label('WF23', x=200, y=57, color=0x000, font=FONT_MONT_14, parent=tab2) touch_button0 = M5Btn(text='STOPP!', x=140, y=69, w=60, h=50, bg_c=0xff0000, text_c=0x000000, font=FONT_MONT_14, parent=tab3) links_drehen_bt = M5Btn(text='<', x=88, y=65, w=50, h=60, bg_c=0x000000, text_c=0xffffff, font=FONT_MONT_22, parent=tab3) vorwaerts_bt = M5Btn(text='^', x=140, y=17, w=60, h=50, bg_c=0x000000, text_c=0xffffff, font=FONT_MONT_26, parent=tab3) rechts_drehen_bt = M5Btn(text='>', x=202, y=65, w=50, h=60, bg_c=0x000000, text_c=0xffffff, font=FONT_MONT_22, parent=tab3) rueckwaerts_bt = M5Btn(text='\/', x=140, y=121, w=60, h=50, bg_c=0x000000, text_c=0xffffff, font=FONT_MONT_14, parent=tab3) def checkbox0_checked(): global data1, name screen.set_screen_brightness(20) pass checkbox0.checked(checkbox0_checked) def checkbox0_unchecked(): global data1, name screen.set_screen_brightness(80) pass checkbox0.unchecked(checkbox0_unchecked) def scan_bt_pressed(): global data1, name geraete_label.set_text('bitte warten...') try : central.scan(10000, on_scan) pass except: geraete_label.set_text('Scan Fehler!') try : central.connect() pass except: geraete_label.set_text('Keine Verbindung moeglich') pass scan_bt.pressed(scan_bt_pressed) def status_bt_2_pressed(): global data1, name try : central.connect() pass except: geraete_label.set_text('Bereits Verbunden..') status_label_2.set_text(str(central.is_connected())) pass status_bt_2.pressed(status_bt_2_pressed) def an_bt_pressed(): global data1, name try : central.write_to('an') pass except: geraete_label.set_text('Fehler!') pass an_bt.pressed(an_bt_pressed) def touch_button_disconnect_pressed(): global data1, name try : central.disconnect() pass except: geraete_label.set_text('Fehler') pass touch_button_disconnect.pressed(touch_button_disconnect_pressed) def aus_bt_pressed(): global data1, name try : central.write_to('aus') pass except: geraete_label.set_text('Fehler!') pass aus_bt.pressed(aus_bt_pressed) def touch_button0_pressed(): global data1, name try : central.write_to('stop') pass except: geraete_label.set_text('Fehler!') pass touch_button0.pressed(touch_button0_pressed) def links_drehen_bt_pressed(): global data1, name try : central.write_to('links_drehen') pass except: geraete_label.set_text('Fehler!') pass links_drehen_bt.pressed(links_drehen_bt_pressed) def vorwaerts_bt_pressed(): global data1, name try : central.write_to('vorwaerts') pass except: geraete_label.set_text('Fehler!') pass vorwaerts_bt.pressed(vorwaerts_bt_pressed) def rechts_drehen_pressed(): global data1, name try : central.write_to('rechts') wait(0.5) central.write_to('normal') pass except: geraete_label.set_text('Fehler!') pass rechts_drehen.pressed(rechts_drehen_pressed) def rechts_drehen_bt_pressed(): global data1, name try : central.write_to('rechts_drehen') pass except: geraete_label.set_text('Fehler!') pass rechts_drehen_bt.pressed(rechts_drehen_bt_pressed) def rueckwaerts_bt_pressed(): global data1, name try : central.write_to('rueckwaerts') pass except: geraete_label.set_text('Fehler!') pass rueckwaerts_bt.pressed(rueckwaerts_bt_pressed) def links_drehen_pressed(): global data1, name try : central.write_to('links') wait(0.5) central.write_to('normal') pass except: geraete_label.set_text('Fehler!') pass links_drehen.pressed(links_drehen_pressed) def on_recv(Data): global data1, name data1 = Data geraete_label.set_text(str(data1)) pass central.on_notify(on_recv) def on_scan(x, y, dev_name): global data1, name name = dev_name if name == '?': geraete_label.set_text('WF23 Saugroboter') else: geraete_label.set_text(str(name)) pass try : central.scan(10000, on_scan) pass except: geraete_label.set_text('Scan Fehler!') try : central.connect() pass except: geraete_label.set_text('keine Verbindung moeglich')
Write, Run & Share Python code online using OneCompiler's Python online compiler for free. It's one of the robust, feature-rich online compilers for python language, supporting both the versions which are Python 3 and Python 2.7. Getting started with the OneCompiler's Python editor is easy and fast. The editor shows sample boilerplate code when you choose language as Python or Python2 and start coding.
OneCompiler's python online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample python program which takes name as input and print your name with hello.
import sys
name = sys.stdin.readline()
print("Hello "+ name)
Python is a very popular general-purpose programming language which was created by Guido van Rossum, and released in 1991. It is very popular for web development and you can build almost anything like mobile apps, web apps, tools, data analytics, machine learning etc. It is designed to be simple and easy like english language. It's is highly productive and efficient making it a very popular language.
When ever you want to perform a set of operations based on a condition IF-ELSE is used.
if conditional-expression
#code
elif conditional-expression
#code
else:
#code
Indentation is very important in Python, make sure the indentation is followed correctly
For loop is used to iterate over arrays(list, tuple, set, dictionary) or strings.
mylist=("Iphone","Pixel","Samsung")
for i in mylist:
print(i)
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while condition
#code
There are four types of collections in Python.
List is a collection which is ordered and can be changed. Lists are specified in square brackets.
mylist=["iPhone","Pixel","Samsung"]
print(mylist)
Tuple is a collection which is ordered and can not be changed. Tuples are specified in round brackets.
myTuple=("iPhone","Pixel","Samsung")
print(myTuple)
Below throws an error if you assign another value to tuple again.
myTuple=("iPhone","Pixel","Samsung")
print(myTuple)
myTuple[1]="onePlus"
print(myTuple)
Set is a collection which is unordered and unindexed. Sets are specified in curly brackets.
myset = {"iPhone","Pixel","Samsung"}
print(myset)
Dictionary is a collection of key value pairs which is unordered, can be changed, and indexed. They are written in curly brackets with key - value pairs.
mydict = {
"brand" :"iPhone",
"model": "iPhone 11"
}
print(mydict)
Following are the libraries supported by OneCompiler's Python compiler
Name | Description |
---|---|
NumPy | NumPy python library helps users to work on arrays with ease |
SciPy | SciPy is a scientific computation library which depends on NumPy for convenient and fast N-dimensional array manipulation |
SKLearn/Scikit-learn | Scikit-learn or Scikit-learn is the most useful library for machine learning in Python |
Pandas | Pandas is the most efficient Python library for data manipulation and analysis |
DOcplex | DOcplex is IBM Decision Optimization CPLEX Modeling for Python, is a library composed of Mathematical Programming Modeling and Constraint Programming Modeling |