Skip to content

Instantly share code, notes, and snippets.

@paulcuth
Last active December 9, 2017 09:44
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulcuth/f646f220a617a5fe43a1 to your computer and use it in GitHub Desktop.
Save paulcuth/f646f220a617a5fe43a1 to your computer and use it in GitHub Desktop.
A choice of quick cheats for those that don't have time to keep referring to the ESP8266 GPIO pin -> IO index map.
-- You could setup global vars:
for k,v in ipairs{3,10,4,9,2,1,nil,nil,nil,11,12,nil,6,7,5,8,0} do _G['GPIO'..k-1]=v end
-- and use them like this:
gpio.mode(GPIO2, gpio.OUTPUT)
gpio.write(GPIO2, gpio.WRITE)
-- Or set them up in the gpio namespace:
gpio=setmetatable({},{__index=gpio}) for k,v in ipairs{3,10,4,9,2,1,nil,nil,nil,11,12,nil,6,7,5,8,0} do gpio['GPIO'..k-1]=v end
-- and use them like this:
gpio.mode(gpio.GPIO2, gpio.OUTPUT)
gpio.write(gpio.GPIO2, gpio.WRITE)
@vehuel
Copy link

vehuel commented May 29, 2015

ipairs is not working for me. The loop stops at first nil value.

Changed ipairs to pairs and worked ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment