return function (connection, req, args) dofile('httpserver-header.lc')(connection, 200, 'html') --define robot dance steps --F=move forward, B=move backward, L=turn left, R=turn right, S=stop local steps = {'R', 'R', 'F', 'F', 'F', 'L', 'F', 'F'} local curStepIdx = 1 --1=GPIO5, 2=GPIO4, 3=GPIO0, 4=GPIO2, 5=GPIO14, 6=GPIO12, --7=GPIO13, 8=GPIO15, 9=GPIO3, 10=GPIO1, 11=GPIO9, 12=GPIO10 local leftpwm, leftpin1, leftpin2 = 1, 2, 4 --GPIO5, GPIO4, GPIO2 local rightpwm, rightpin1, rightpin2 = 5, 6, 7 --GPIO14, GPIO12, GPIO13 local tmrId, tmrMs = 4, 1000 -- init motors pwm.setup(leftpwm, 500, 1023) pwm.start(leftpwm) gpio.mode(leftpin1, gpio.OUTPUT) gpio.mode(leftpin2, gpio.OUTPUT) pwm.setup(rightpwm, 500, 1023) pwm.start(rightpwm) gpio.mode(rightpin1, gpio.OUTPUT) gpio.mode(rightpin2, gpio.OUTPUT) --run step every tmr.alarm(tmrId, tmrMs, tmr.ALARM_SEMI, function() local curStep = steps[curStepIdx] if (curStep ~= nil) then if (curStep == 'F') then gpio.write(leftpin1, gpio.LOW) gpio.write(leftpin2, gpio.HIGH) gpio.write(rightpin1, gpio.LOW) gpio.write(rightpin2, gpio.HIGH) elseif (curStep == 'B') then gpio.write(leftpin1, gpio.HIGH) gpio.write(leftpin2, gpio.LOW) gpio.write(rightpin1, gpio.HIGH) gpio.write(rightpin2, gpio.LOW) elseif (curStep == 'L') then gpio.write(leftpin1, gpio.LOW) gpio.write(leftpin2, gpio.HIGH) gpio.write(rightpin1, gpio.HIGH) gpio.write(rightpin2, gpio.LOW) elseif (curStep == 'R') then gpio.write(leftpin1, gpio.HIGH) gpio.write(leftpin2, gpio.LOW) gpio.write(rightpin1, gpio.LOW) gpio.write(rightpin2, gpio.HIGH) elseif (curStep == 'S') then gpio.write(leftpin1, gpio.LOW) gpio.write(leftpin2, gpio.LOW) gpio.write(rightpin1, gpio.LOW) gpio.write(rightpin2, gpio.LOW) end curStepIdx = curStepIdx + 1 tmr.start(tmrId) else gpio.write(leftpin1, gpio.LOW) gpio.write(leftpin2, gpio.LOW) gpio.write(rightpin1, gpio.LOW) gpio.write(rightpin2, gpio.LOW) end end) connection:send([===[ robot.lua

Running!

]===]) end