We're no longer updating This wiki!!

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
en:c1_tinkering [2015/11/23 12:20]
odroid [Android]
en:c1_tinkering [2016/02/29 14:25]
john1117 removed
Line 184: Line 184:
 //​------------------------------------------------------------------------------------------------------------ //​------------------------------------------------------------------------------------------------------------
 //​------------------------------------------------------------------------------------------------------------ //​------------------------------------------------------------------------------------------------------------
 +</​file>​
 +
 +== Python example ==
 +  * [[https://​github.com/​hardkernel/​WiringPi2-Python|WiringPi2-Python repository for ODROID]]
 +**Prerequisites**:​ You must have //​python-dev//​ and //​python-setuptools//​ installed If you manually rebuild the bindings with swig-python wiringpi.i
 +
 +1. Get/setup WiringPi 2 for Python repository
 +<​code>​
 +# git clone https://​github.com/​hardkernel/​WiringPi2-Python.git
 +# cd WiringPi2-Python
 +# git submodule init
 +# git submodule update
 +</​code>​
 +
 +2. Build & install
 +<​code>​
 +# sudo python setup.py install
 +</​code>​
 +
 +3. Run the example source code
 +<file python example-led.py>​
 +#​!/​usr/​bin/​python
 +import wiringpi2 as wpi
 +import time
 +
 +leds = [24, 23, 22, 21, 14, 13, 12, 3, 2, 0, 7, 1, 4, 5, 6, 10, 26, 11, 27]
 +
 +wpi.wiringPiSetup()
 +
 +# GPOI pin setup
 +for x in leds:
 + wpi.pinMode(x,​ 1)
 + wpi.digitalWrite(x,​ 0)
 +
 +adc_unit = 4095 / len(leds)
 +while True:
 + time.sleep(0.05)
 +
 + # Read the adc value
 + adcValue = wpi.analogRead(0)
 +
 + # Set the LEDs
 + ledPos = (adcValue * len(leds) * 1000) / 1024
 + ledPos = len(leds) - (ledPos / 1000)
 +
 + for x in leds:
 + wpi.digitalWrite(x,​ 0)
 +
 + for x in xrange(ledPos):​
 + wpi.digitalWrite(leds[x],​ 1)
 </​file>​ </​file>​
  
en/c1_tinkering.txt ยท Last modified: 2017/03/27 09:38 by brian.kim
CC Attribution-Share Alike 3.0 Unported
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0