Using C# and GPIO - Raspberry Pi Forums
hello everybody,
i'm new raspberry i'm senior developper in c#. i'm using raspberry house automation (so i've added razberry), , particulary analyze electrical/water/gaz consommation.
first step using pulse counter, connecting them gpio. i'm confortable c#, i'd use achieve goal.
there's not c# on raspberry compare c/c++ or python, that's why i'm asking guys advice me what's best library ?
lot !
i'm new raspberry i'm senior developper in c#. i'm using raspberry house automation (so i've added razberry), , particulary analyze electrical/water/gaz consommation.
first step using pulse counter, connecting them gpio. i'm confortable c#, i'd use achieve goal.
there's not c# on raspberry compare c/c++ or python, that's why i'm asking guys advice me what's best library ?
lot !
you need download attached zip file, 2 files need in exe path. plus, need make reference dll.
here very simple winform app run in rasbian x desktop. reads state of switch , outputs leds.
hope helps, , basic without error checking. needed test stuff out.
here pinout

console app turn on leds code: select all
using system; using raspberrypidotnet; namespace test { class program { static void main(string[] args) { gpiomem led15 = new gpiomem(gpiopins.v2_gpio_15); gpiomem led18 = new gpiomem(gpiopins.v2_gpio_18); while(true) { led15.write(pinstate.high); system.threading.thread.sleep(200); led15.write(pinstate.low); //system.threading.thread.sleep(50); led18.write(pinstate.high); system.threading.thread.sleep(200); led18.write(pinstate.low); //system.threading.thread.sleep(50); } } } }
here very simple winform app run in rasbian x desktop. reads state of switch , outputs leds.
code: select all
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.windows.forms; using raspberrypidotnet; namespace pi_form_led_app { public partial class form1 : form { gpiomem led15 = new gpiomem(gpiopins.v2_gpio_15); gpiomem led18 = new gpiomem(gpiopins.v2_gpio_18); gpiomem led24 = new gpiomem(gpiopins.v2_gpio_24,gpiodirection.in); public form1() { initializecomponent(); } private void chkred_checkedchanged(object sender, eventargs e) { if (chkred.checked) { led15.write(pinstate.high); } else { led15.write(pinstate.low); } } private void chkgreen_checkedchanged(object sender, eventargs e) { if (chkgreen.checked) { led18.write(pinstate.high); } else { led18.write(pinstate.low); } } private void form1_load(object sender, eventargs e) { } private void button1_click(object sender, eventargs e) { } private void timer1_tick(object sender, eventargs e) { chkswitch.text = led24.read().tostring(); } private void btnflash_click(object sender, eventargs e) { if (btnflash.text == "start flashing") { timer2.start(); btnflash.text = "stop flashing"; } else { timer2.stop(); btnflash.text = "start flashing"; led15.write(pinstate.low); led18.write(pinstate.low); } } private void timer2_tick(object sender, eventargs e) { led15.write(pinstate.high); system.threading.thread.sleep(100); led15.write(pinstate.low); led18.write(pinstate.high); system.threading.thread.sleep(100); led18.write(pinstate.low); } } }
here pinout
raspberrypi
Comments
Post a Comment