-- John Longworth June 2017 -- Program for Yellow WiFi Development Kit g = 6 -- Pin D6/GPIO12 connected to green LED b = 7 -- Pin D7/GPIO13 connected to blue LED r = 8 -- Pin D8/GPIO15 connected to red LED blueLED = 0 -- NOTE setting all pins LOW turns off the RGB LED -- and turns on the 6 SMD red (and blue) LEDS function init() -- Set pins 0 to 8 to output for i = 0, 8 do gpio.mode(i,gpio.OUTPUT) gpio.write(i,gpio.LOW) end end function allOff() -- Turn off all 3 colours of RGB LED gpio.write(g,gpio.LOW) gpio.write(b,gpio.LOW) gpio.write(r,gpio.LOW) end function setRGB() tmr.alarm(0,1000,0,function() -- Turn on red LED after 1 second allOff() gpio.write(r,gpio.HIGH) end) tmr.alarm(1,2000,0,function() -- Turn on green LED after 2 seconds allOff() gpio.write(g,gpio.HIGH) end) tmr.alarm(2,3000,0,function() -- Turn on blue LED after 3 seconds allOff() gpio.write(b,gpio.HIGH) end) end function flashRed() led = node.random(0, 5) -- Choose a red LED between 0 an 5 if led == 4 then -- Don't do anything with D4/GPIO2 led = 1 -- led could be any number (0,1,2,3,5) end gpio.write(led ,node.random(0, 1)) -- Turn LED on or off (0 or 1) end -- Flash blue LED every 500 milliseconds function flashBlue() -- Blue LED on ESP-12 is connected to pin D4/GPIO2 tmr.alarm(4,500,1,function() gpio.write(4,blueLED) blueLED = blueLED + 1 if blueLED == 2 then blueLED = 0 end flashRed() end) end init() flashBlue() count = 0 tmr.alarm(3,4000,1,function() count = count + 1 if count == 4 then -- Read ADC after 4th time i.e. every 16 seconds print("ADC = ", adc.read(0)) -- ADC connected to pin A0 count = 0 end setRGB() end)