Homepage Wiki Forum Buy

Python

Aus GNUBLIN

Inhaltsverzeichnis

Python Skripte

hello.py

#!/usr/bin/python
# Hello world python program

print "Hello World!";


Ausführen:

python hello.py


Anwedungs Beispiele

LED BLINK

Das folgende Script lässt die LED an GPIO3 blinken.

 #!/usr/bin/python
 import sys, time, os

 GPIO = "3"
 gpio_unexport = open('/sys/class/gpio/unexport','w')
 gpio_unexport.write(GPIO)
 gpio_unexport.close() 

 gpio_export = open('/sys/class/gpio/export','w')
 gpio_export.write(GPIO)
 gpio_export.close()


 tmp = "/sys/class/gpio/gpio" + GPIO + "/direction"
 gpio_direction = open('tmp','w')
 gpio_direction.write("out")
 gpio_direction.close()

 
 tmp1 = "echo 1 > " + "/sys/class/gpio/gpio" + GPIO + "/value"
 tmp0 = "echo 0 > " + "/sys/class/gpio/gpio" + GPIO + "/value"
 while 1:
    os.system(tmp1)
    time.sleep(1)
    os.system(tmp0)
    time.sleep(1)

 

PWM

PWM Beispiel

In anderen Sprachen