Intro: Python:Run Python on PcDuino
Python is a widely used general-purpose, high-level
programming language.Its design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code than would be possible in languages such as C.The language provides constructs intended to enable clear programs on both a small and large scale.
Python supports multiple programming paradigms, including object-oriented, imperative and functional programming orprocedural styles. It features a dynamic type system and automatic memory management and has a large and comprehensive standard library.
Like other dynamic languages, Python is often used as a scripting language, but is also used in a wide range of non-scripting contexts. Using third-party tools, such as Py2exe, or Pyinstaller,Python code can be packaged into standalone executable programs. Python interpreters are available for many operating systems.
Python is preloaded in pcDuino 20130531 and later version. (The example program of Python can be download on the github).
Here with a ‘ HelloWord’ program to introduce how to use the Python on pcDuino)
(1) Create a file named as helloword.py
$ vim helloword.py
(2)Write simple Python code in the new file ‘.py’ .
print （“Hello Word !”）
(3)Run the script of Python.
$ python ./helloword.py
Following is a simple routine:Let variable value add 1 every 1s, add to 256 then reset to zero
i = 0 disp_delay = 0 def delay(ms): time.sleep(1.0*ms/1000) def setup(): global i,disp_delay i = 0 disp_delay = 1000 def loop(): global i,disp_delay i = i + 1 if(i == 256): i = 0; print ("i = %d" %i) delay(disp_delay) #main function setup() while True: loop()