09.11.2012 Views

Contents - Raspberry PI Community Projects

Contents - Raspberry PI Community Projects

Contents - Raspberry PI Community Projects

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

# call set_debug(1) to do a non-destructive test on non-RPi hardware<br />

#Device::BCM2835::set_debug(1);<br />

Device::BCM2835::init()<br />

|| die "Could not init library";<br />

# Blink pin 11:<br />

# Set RPi pin 11 to be an output<br />

Device::BCM2835::gpio_fsel(&Device::BCM2835::R<strong>PI</strong>_G<strong>PI</strong>O_P1_11,<br />

&Device::BCM2835::BCM2835_G<strong>PI</strong>O_FSEL_OUTP);<br />

while (1)<br />

{<br />

# Turn it on<br />

Device::BCM2835::gpio_write(&Device::BCM2835::R<strong>PI</strong>_G<strong>PI</strong>O_P1_11, 1);<br />

Device::BCM2835::delay(500); # Milliseconds<br />

# Turn it off<br />

Device::BCM2835::gpio_write(&Device::BCM2835::R<strong>PI</strong>_G<strong>PI</strong>O_P1_11, 0);<br />

Device::BCM2835::delay(500); # Milliseconds<br />

}<br />

G<strong>PI</strong>O Driving Example (C#)<br />

<strong>Raspberry</strong>PiDotNet library is available at https://github.com/cypherkey/<strong>Raspberry</strong>Pi.Net/.<br />

The library includes a G<strong>PI</strong>OFile and G<strong>PI</strong>OMem class. The G<strong>PI</strong>OMem requires compiling<br />

Mike McCauley's bcm2835 library above in to a shared object.<br />

using System;<br />

using System.Collections.Generic;<br />

using System.Linq;<br />

using System.Text;<br />

using <strong>Raspberry</strong>PiDotNet;<br />

using System.Threading;<br />

namespace RaspPi<br />

{<br />

class Program<br />

{<br />

static void Main(string[] args)<br />

{<br />

// Access the G<strong>PI</strong>O pin using a static method<br />

G<strong>PI</strong>OFile.Write(G<strong>PI</strong>O.G<strong>PI</strong>OPins.G<strong>PI</strong>O00, true);<br />

}<br />

}<br />

}<br />

// Create a new G<strong>PI</strong>O object<br />

G<strong>PI</strong>OMem gpio = new G<strong>PI</strong>OMem(G<strong>PI</strong>O.G<strong>PI</strong>OPins.G<strong>PI</strong>O01);<br />

gpio.Write(false);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!