All that is acquired by overwork & lt; code class = & quot; cpp & quot; & gt; // beta 3 - calibrated range of the distance to a pro rata adjustment of brightness and hue // beta 4 - added Tally switchable external light, lamp remote control // beta 4 - compression of the input temperature values for fixed color temperatures // beta 4 - adjust the color temperature: / * -35 - -25 -25 0 Blue - Turquoise 15 -15 -15 - Light cyan 0 50 0 - 15 Light Green 85 15 - 20 100 Green 20 - 25 Yellow-green 170 25 - 30 Yellow-Red Raspberry 30+ 235 254 // RED: if (colorV & lt; 100) {targetR = colorV * 0.05; } Else {targetR = 5+ (colorV-100) * 1.29; } // GREEN if (colorV & lt; 75) {// 0 - 180 targetG = 2.4 * colorV; } If (colorV & gt; 75 & amp; & amp; colorV & lt; 100) // {180 - 254 targetG = 180 + (colorV-75) 2.96 *; } If (colorV & gt; 100 & amp; & amp; colorV & lt; 150) {// 254 targetG = 254; } If (colorV & gt; 150 & amp; & amp; colorV & lt; 200) // {254 - 154 targetG = 254 - (colorV-150) * 2; } If (colorV & gt; 200) {// 154 - 0 targetG = 154 - (colorV-200) * 2.85; } // BLUE if (colorV & lt; 100) {targetB = 254 - colorV * 2.54; } Else {targetB = colorV * 0.05; } * / #include & Lt; RCSwitch.h & gt; // Control sockets SC2260 / 2262 http://code.google.com/p/rc-switch/ #include & lt; livolo.h & gt; // Control switches Livolo #define txPin 8 // pin transmitter Livolo livolo (8); // Object Livolo RCSwitch mySwitch = RCSwitch (); // Object RC-Switch int weatherData = 0; unsigned long dimmerDelay, timerStart, timerStop, timerSwitchStart, timerSwitchStop, timerRange; // Timers int prevRange, nowRange, tempRange, switchRange, vectorRange, initRange, rangeFinder, tempC; byte nightLightLevel, rainbow, delta, redB, greenB, blueB, targetL, targetR, targetG, targetB, lastValueRGB; byte lightMode = 0; // Mode lamp (0 - nightlight 1 - lamp, 2 - thermometer, 3 - rainbow manual, 4 - Rainbow automatic) byte lastMode = 1; // Mode for the first call always lamp byte valueRGB = 0; // Brightness or hue (normalized value nowRange) boolean rainbowUp, followMeLight; // Direction rainbow boolean timing = false; // Sign running timer (hand over the lamp) boolean switchLock = false; // Sign the ban on switching to the removal of the hand lamp with boolean tempLock = false; // Sign a ban on the display temperature to produce a new boolean backLight = false; // Sign running back light boolean mainLight = false; // Sign of working skylight boolean nightLight = false; // Sign nightlight mode boolean tempRcvd = false; // Sign of the resulting temperature 65 // #define nightLightLimit brightness nightlight #define rangePin A0 // #define redPin obstacle sensor 9 // #define greenPin red green 10 // 11 // #define bluePin blue #define bottom 630 // bottom zone adjustment // #define top 135 top zone adjustment 20 // #define delta allowable deviation in determining the distance #define shortDelay 350 // delay for switching modes #define longDelay 3000 100 // #define timeOutRange spacing distance calculation is needed since & quot ; slip & quot; hand distance varies, and thus changing the brightness or color #define rainbowStep 75 // change interval shade of the rainbow 35 // #define dimmerStep speed mute nightlight void setup () {// Serial.begin (9600); pinMode (rangePin, INPUT); pinMode (redPin, OUTPUT); pinMode (greenPin, OUTPUT); pinMode (bluePin, OUTPUT); mySwitch.enableTransmit (txPin); // Allowed to remain mySwitch.enableReceive (0); // Allowed reception (interrupt 0 - & gt; pin 2) rgbLight (0, 0, 0); // Lamp is turned off lastMode = 1; // First inclusion is always in the mode of light timerRange = millis (); // Start the timer to periodically reading distance nowRange = getRange (); // First calculation distance} void loop () {// periodically calculating DISTANCE if ((millis () - timerRange) & gt; timeOutRange) {// distance calculation times timeOutRange prevRange = nowRange; // Memory of the previous value of the distance nowRange = getRange (); // The current value of the distance timerRange = millis (); // Reset the timer interval calculation distance // Serial.print (& quot; Range: & quot;); // Serial.println (nowRange); } // Ran his hand - start the timer and switching (if appropriate), detained hand - service functions (if needed) if ((nowRange & lt; bottom + delta) & amp; & amp; (nowRange & gt; top)) {// if the distance is greater than the threshold and less than the upper boundary if (nowRange & gt; bottom - delta) {// off the light before & quot; bottom & quot; as an indicator for holding hands with complete exclusion of (2 * delta) valueRGB = 0; } Else {valueRGB = 254 - map (nowRange, top, bottom, 0, 254); // Cast the current value to a range of 0 - 254 and & quot; revolution & quot; } // Serial.print (& quot; valueRGB: & quot;); // Serial.println (valueRGB); // Color map to change the background and skylight if (lightMode == 1) {// if the lamp mode if (valueRGB & gt; 70 & amp; & amp; valueRGB & lt; 110) {// if the hand in the middle of the lower half of followMeLight = true ; // Kill bit dimming white light is allowed only shade indicator lastValueRGB = valueRGB; // Memory of the last brightness values rgbLight (0, 255, 0); // Green color as an indicator of the ability to switch & quot; near & quot; Light // Serial.println (& quot; Set Green to 255 & quot;); } Else {if (valueRGB & gt; 175 & amp; & amp; valueRGB & lt; 215) {// if the hand in the middle of the upper half followMeLight = true; lastValueRGB = valueRGB; // Memory of the last brightness values rgbLight (0, 0, 255); // Blue color as an indicator of the ability to switch & quot; far & quot; Light // Serial.println (& quot; Set Blue to 255 & quot;); } Else {if (valueRGB & gt; 235) {// if the hand is at the upper limit followMeLight = true; lastValueRGB = valueRGB; // Memory of the last brightness values rgbLight (valueRGB, 0, 0);