Advertisement
pastukhov

rgb.lua

Apr 14th, 2015
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.90 KB | None | 0 0
  1. red = 9
  2. green = 10
  3. blue = 3
  4.  
  5.  
  6. local function rgbinit()
  7.       print("Setting up pwm")
  8.       pwm.setup(red,1023,0)
  9.       pwm.setup(green,1023,0)
  10.       pwm.setup(blue,1023,0)
  11.       pwm.start(red)
  12.       pwm.start(green)
  13.       pwm.start(blue)
  14.       isInit = true
  15. end
  16.  
  17.  
  18. local function led(r,g,b)
  19.   if isInit then
  20.      if r then pwm.setduty(red,r) end
  21.      if g then pwm.setduty(green,g) end
  22.      if b then pwm.setduty(blue,b) end
  23.   else
  24.      rgbinit()
  25.      if r then pwm.setduty(red,r) end
  26.      if g then pwm.setduty(green,g) end
  27.      if b then pwm.setduty(blue,b) end
  28.   end
  29. end
  30.  
  31.  
  32.  
  33. return function (connection, args)
  34.    print('The color is ', args.r,args.g,args.b)
  35.     led(args.r,args.g,args.b)
  36.    connection:send("HTTP/1.0 200 OK\r\nContent-Type: application/json\r\nCache-Control: private, no-store\r\n\r\n")
  37.    connection:send('{"error":0, "message":"OK", "heap":'..node.heap()..'}')
  38. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement