Please select To the mobile version | Continue to access the desktop computer version

OrangePi

 Login            
 Register            
Search
Hot search: orangepi
View: 2877|Reply: 0

Python:Run Python on pcDuino

[Copy link]

17

Threads

17

Posts

91

Credits

Registered member

Rank: 2

Credits
91
Post time 2016-10-25 16:52:19 | Show all posts |Read mode


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 routineet variable value add 1 every 1s, add to 256 then reset to zero
  1. import time
  2. i = 0
  3. disp_delay = 0

  4. def delay(ms):
  5.         time.sleep(1.0*ms/1000)

  6. def setup():
  7.         global i,disp_delay
  8.         i = 0
  9.         disp_delay = 1000

  10. def loop():
  11.         global i,disp_delay
  12.         i = i + 1
  13.         if(i == 256):
  14.                 i = 0;
  15.         print ("i = %d" %i)
  16.         delay(disp_delay)

  17. #main function
  18. setup()
  19. while True:
  20.         loop()
  21. <img alt="image3" src="http://cnlearn.linksprite.com/wp-content/uploads/2014/02/%E5%9B%BE%E7%89%8735.png" />
Copy the Code

You have to log in before you can reply Login | Register

Points Rules

Archiver|Mobile edition|Darkroom|OrangePi En ( 粤ICP备14086627号-2

2019-11-17 07:48 GMT+8 , Processed in 0.029992 second(s), 23 queries .

Powered by Discuz! X3.2

© 2014-2015 orangepibbs en.

Quick Reply To Top Return to the list