GithubHelp home page GithubHelp logo

bcm2835pii's Introduction

bcm2835pii - nim lang

bcm2835 basic gpio functions: i/o, pull-up/down
for raspberry pi B+ boards until pi3

created as a companion-lib for nimgpiod

optionally depends on bcm_host lib - it is the new preferred way for hardware detection by raspberrypi.org

compiler definitions:

-d:dependency_free : do not import bcm_host
-d:safetyOn : check for possibly harmful gpio mode operations (...)

when isMainModule:
  import strformat

  var errno = init()
  if errno < 0:
    echo "init failure ", errno
  else:
    echo "init success"
    let Gpio12: Gpio = 12
   
    for i in 0..15:
      var 
        g_mode = getMode(i)
        g_lvl = getLevel(i)

      echo &"GPIO {i:>2d}\t{g_mode}\t{g_lvl}"
    
    # set pull
    echo "gpio mode ", getMode(Gpio12)
    echo "getLevel ", getLevel(Gpio12)
    setPull(Gpio12, Pull.Up)
    echo "gpio mode ", Gpio12.mode
    echo "getLevel ", Gpio12.level
    setPull(Gpio12, Pull.Down)
    echo "gpio mode ", getMode(Gpio12)
    echo "getLevel ", getLevel(Gpio12)

    # set mode
    echo "gpio mode ", GpioMode(getMode(Gpio12))
    echo "gpio SET mode Alt0 "
    setMode(Gpio12,GpioMode.Alt0)
    echo "gpio mode ", GpioMode(getMode(Gpio12))

    echo "gpio SET mode Output "
    Gpio12.mode = GpioMode.Output
    echo "gpio mode ", GpioMode(Gpio12.mode)
    echo "getLevel ", Gpio12.level
    echo "  setLevel 1 "
    setLevel(Gpio12, 1)
    echo "getLevel ", getLevel(Gpio12)
    echo "gpio SET mode Input "
    setMode(Gpio12,GpioMode.Input)
    echo "gpio mode ", GpioMode(getMode(Gpio12))

    when defined(safetyOn):
      echo "#######################################"
      echo " safety check - should abort in 3..2.."
      setMode(Gpio(0),GpioMode.Input)

bcm2835pii's People

Contributors

nais314 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.