-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add missing globals from luacheck config * Fix luacheck warnings in all lua files * Re-enable luacheck in Travis * Speed up Travis by using preinstalled LuaRocks * Fix more luacheck warnings in httpserver lua module * Fix DCC module and add appropriate definitions to luacheck config. * Change inline comments from ignoring block to only ignore specific line * Add Luacheck for Windows and enable it for both Windows and Linux * Change luacheck exceptions and fix errors from 1st round of polishing * Add retry and timeout params to wget
- Loading branch information
1 parent
1652c0c
commit bcb669a
Showing
67 changed files
with
905 additions
and
718 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,47 @@ | ||
-- | ||
-- Light sensor on ADC(0), RGB LED connected to gpio12(6) Green, gpio13(7) Blue & gpio15(8) Red. | ||
-- Light sensor on adc0(A0), RGB LED connected to gpio12(D6) Green, gpio13(D7) Blue & gpio15(D8) Red. | ||
-- This works out of the box on the typical ESP8266 evaluation boards with Battery Holder | ||
-- | ||
-- It uses the input from the sensor to drive a "rainbow" effect on the RGB LED | ||
-- Includes a very "pseudoSin" function | ||
-- | ||
-- Required C Modules: adc, tmr, pwm | ||
|
||
function led(r,Sg,b) | ||
pwm.setduty(8,r) | ||
pwm.setduty(6,g) | ||
pwm.setduty(7,b) | ||
local redLed, greenLed, blueLed = 8, 6, 7 | ||
|
||
local function setRGB(r,g,b) | ||
pwm.setduty(redLed, r) | ||
pwm.setduty(greenLed, g) | ||
pwm.setduty(blueLed, b) | ||
end | ||
|
||
-- this is perhaps the lightest weight sin function in existance | ||
-- Given an integer from 0..128, 0..512 appximating 256 + 256 * sin(idx*Pi/256) | ||
-- this is perhaps the lightest weight sin function in existence | ||
-- Given an integer from 0..128, 0..512 approximating 256 + 256 * sin(idx*Pi/256) | ||
-- This is first order square approximation of sin, it's accurate around 0 and any multiple of 128 (Pi/2), | ||
-- 92% accurate at 64 (Pi/4). | ||
function pseudoSin (idx) | ||
idx = idx % 128 | ||
lookUp = 32 - idx % 64 | ||
val = 256 - (lookUp * lookUp) / 4 | ||
if (idx > 64) then | ||
val = - val; | ||
end | ||
return 256+val | ||
-- 92% accurate at 64 (Pi/4). | ||
local function pseudoSin(idx) | ||
idx = idx % 128 | ||
local lookUp = 32 - idx % 64 | ||
local val = 256 - (lookUp * lookUp) / 4 | ||
if (idx > 64) then | ||
val = - val; | ||
end | ||
return 256+val | ||
end | ||
|
||
pwm.setup(6,500,512) | ||
pwm.setup(7,500,512) | ||
pwm.setup(8,500,512) | ||
pwm.start(6) | ||
pwm.start(7) | ||
pwm.start(8) | ||
do | ||
pwm.setup(redLed, 500, 512) | ||
pwm.setup(greenLed,500, 512) | ||
pwm.setup(blueLed, 500, 512) | ||
pwm.start(redLed) | ||
pwm.start(greenLed) | ||
pwm.start(blueLed) | ||
|
||
tmr.alarm(1,20,1,function() | ||
idx = 3 * adc.read(0) / 2 | ||
r = pseudoSin(idx) | ||
g = pseudoSin(idx + 43) | ||
b = pseudoSin(idx + 85) | ||
led(r,g,b) | ||
idx = (idx + 1) % 128 | ||
end) | ||
tmr.create():alarm(20, tmr.ALARM_AUTO, function() | ||
local idx = 3 * adc.read(0) / 2 | ||
local r = pseudoSin(idx) | ||
local g = pseudoSin(idx + 43) -- ~1/3rd of 128 | ||
local b = pseudoSin(idx + 85) -- ~2/3rd of 128 | ||
setRGB(r,g,b) | ||
end) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.