Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/share/examples/lua GPIO pins are 0 based when accessed from ...



details:   https://anonhg.NetBSD.org/src/rev/04c0427e985d
branches:  trunk
changeset: 777604:04c0427e985d
user:      mbalmer <mbalmer%NetBSD.org@localhost>
date:      Sat Feb 25 09:13:38 2012 +0000

description:
GPIO pins are 0 based when accessed from Lua, not 1 based like Lua usually
is.  The pulse() has been removed, use gpiopwm(4) for that.

diffstat:

 share/examples/lua/gpio.lua |  19 ++++++++-----------
 1 files changed, 8 insertions(+), 11 deletions(-)

diffs (37 lines):

diff -r 790d22b0db02 -r 04c0427e985d share/examples/lua/gpio.lua
--- a/share/examples/lua/gpio.lua       Sat Feb 25 02:43:08 2012 +0000
+++ b/share/examples/lua/gpio.lua       Sat Feb 25 09:13:38 2012 +0000
@@ -1,4 +1,4 @@
--- $NetBSD: gpio.lua,v 1.1 2011/10/15 12:58:43 mbalmer Exp $
+-- $NetBSD: gpio.lua,v 1.2 2012/02/25 09:13:38 mbalmer Exp $
 
 require 'gpio'
 
@@ -12,20 +12,17 @@
 
 print('gpio0 has ' .. npins .. ' pins.')
 
-for n = 1, npins do
+for n = 0, npins - 1 do
        print('pin ' .. n .. ': ' .. g:read(n))
 end
 
-local oldval = g:write(32, gpio.PIN_HIGH)
-print('pin 32: ' .. oldval .. ' -> ' .. g:read(32))
-
-oldval = g:toggle(32)
-print('pin 32: ' .. oldval .. ' -> ' .. g:read(32))
+local oldval = g:write(31, gpio.PIN_HIGH)
+print('pin 31: ' .. oldval .. ' -> ' .. g:read(31))
 
-g:pulse(32, 1, 50)
-g:write(1, gpio.PIN_LOW)
+oldval = g:toggle(31)
+print('pin 31: ' .. oldval .. ' -> ' .. g:read(31))
 
-g:write(32, gpio.PIN_LOW)
+g:write(31, gpio.PIN_LOW)
 
-g:write(32, 5)
+g:write(31, 5)
 



Home | Main Index | Thread Index | Old Index