Skip to content

Instantly share code, notes, and snippets.

@paulcuth
Last active Dec 9, 2017
Embed
What would you like to do?
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