GPIO with PWM
C++
The example code for GPIO on mraa usage with C++ can be found from: https://github.com/intel-iot-devkit/joule-code-samples/tree/master/exploring-cpp/lesson_2_gpio
.
Python
Example of using LEDs in Python:
To turn on LED100:
root@intel-corei7-64:~# python
Python 2.7.12 (default, Dec 27 2016, 18:31:23)
[GCC 5.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mraa
>>> led = mraa.Gpio(100)
>>> led.dir(mraa.DIR_OUT)
>>> led.write(1)
To show LEDs rotating, generate file
leds.py
:import mraa
import time
def main():
# Define the leds from expansion board
leds = [mraa.Gpio(100), mraa.Gpio(101), mraa.Gpio(102), mraa.Gpio(103)]
for led in leds:
led.dir(mraa.DIR_OUT) # set GPIO to be output
while(1):
for led in leds:
led.write(1) # set led on
print("Led" + str(leds.index(led))+" status: " + str(led.read()))
time.sleep(0.3)
led.write(0) # set led off
print("Led" + str(leds.index(led))+" status: " + str(led.read()))
if __name__ == "__main__": main()
Then run from command line:
root@intel-corei7-64:~# python leds.py
Press ctrl-c to stop.