& lt; code class = & quot; cpp & quot; & gt; // Special Lieb, which reduces the latency when using digitalRead \ digitalWrite. #include & lt; digitalWriteFast.h & gt; int led = 7; // Ping, which is connected indicator LED int mov = 5; // Ping, where the motion sensor is connected int tra = 9; // Ping, which is connected gate of the FET int up = 12; // Pin, where Pin A int down = 11; // Pin where Pin B int swi = 10; // Pin, where Pin C int swi1 = 6; // Pin, where Pin D String btn; int tmp; int mv; int timer, inttimer; // Timer variable int br = 255; // Brightness LED default int cur = 255; // Service variable brightness int stepp = 5; // How much to change the brightness int moved; // Symptom work after going int out = 3600; // Timeout after which the light is switched off int svet = 60; // How many turn on the lights when driving at night void setup () {pinMode (led, OUTPUT); pinMode (tra, OUTPUT); pinMode (13, OUTPUT); pinMode (mov, INPUT); pinMode (up, INPUT); pinMode (down, INPUT); pinMode (swi, INPUT); timer = 0; Serial.begin (9600); analogWrite (tra, 255); } Void loop () {// We increase timers timer ++; inttimer ++; int sensorValue = analogRead (A0); // Read the brightness of light mv = mv + digitalReadFast (mov); if (mv == 7) {mv = 0;} // Count how many movements, and reset if they like 7 btn = buttonpressed (); // Read which button was pressed on the remote // If the button is pressed, the forming of action if (btn! = & Quot; & quot;) {if (br & gt; 10) {stepp = 10;} // If the current value is greater than 10 then increment set to 10. This makes for a more noticeable change in brightness if (btn == & quot; a & quot;) {br = br + stepp;} if (btn == & quot; b & quot;) {br = br-stepp;} if (btn == & quot; c & quot;) {// If pressing the Option key timeout, then if (out == 7200) {out = 3600; blink (8, 50); delay (1000);} else // If the current time-out for two hours, then reset for an hour, and blimkaem 8 times if (out == 1800) {out = 7200; blink (0, 2000); delay (1000);} else // If the current timeout for half an hour, then put on two and one blimkaem long time if (out == 3600) {out = 1800; blink (50, 15); delay (1000);} // If the current timeout hour, then put on the half hour and Flashing light} if (br & lt ; 0) {br = 255;} // If the brightness threshold too low, then set to maximum (turn on the light) if (br & gt; 255) {br = 0;} // If the brightness threshold is exceeded, then reset to 0 (disable light ) cur = br; analogWrite (tra, br); // Set the voltage at the output of the PWM Arduino, and accordingly the gate tranzictora // Reset variables after pressing each button timer = 0; inttimer = 0; moved = 0; delay (250); } // If there was a motion is detected, the counting starts again if (digitalReadFast (mov) == 1) {timer = 0; digitalWriteFast (13, HIGH); } Else {digitalWriteFast (13, LOW); } If ((br & gt; 240) and (inttimer == 1800)) {br = 180; cur = 180; analogWrite (tra, cur);} // If it's been half an hour, and the brightness of the lamps is high, then reset it a bit // To achieve a certain timer gradually extinguish the light, but to recover, if at this moment to detect motion if (timer == out) {for (int i = br; i & gt; = 0; i--) {analogWrite (tra, i); br = 0; if (digitalReadFast (mov) == 1) {timer = 0; br = cur; analogWrite (tra, cur); break; } Delay (100); }} // If the timer load nightlight on and off the light if ((timer == svet) and (moved == 1)) {br = 0; moved = 0; mv = 0; cur = 0; analogWrite (tra, br); } // If there were motion and brightness of the lamp - a zero, then turn on the light in the Pyaterochka and reset the timer if ((mv & gt; 5) and (br == 0) and (sensorValue & gt; 1020)) {br = 5; cur = 5; timer = 0; moved = 1; mv = 0; analogWrite (tra, br); }} Void blink (int count, int del) {for (int i = 0; i & lt; = count; i ++) {// sets the value (range from 0 to 255): delay (del); digitalWriteFast (led, HIGH); delay (del); digitalWriteFast (led, LOW); }} String buttonpressed () // function to determine the crutch-pressing the keypad + pause {btn = & quot; & quot ;; for (int i = 0; i & lt; = 1000; i ++) {if (digitalReadFast (down) == 1) {btn = & quot; b & quot ;;} if (digitalReadFast (up) == 1) {btn = & quot; a & quot ;;} if (digitalReadFast (swi) == 1) {btn = & quot; c & quot ;;} if (digitalReadFast (swi1) == 1) {btn = & quot; d & quot ;;} if (btn! = & quot; & quot ;) {blink (0, 20); break;} delay (1); } Return btn; } & Lt; / code & gt; pre>
A bit workflow: h5>
A little video demonstration: h5>
bit of a disappointment: h5> - The design, which was filmed on video - is unusable. Two 20-watt LED warm light raskochegarilsya radiator to such an extent that the molten tin, which to them were soldered wires. Replaced two 20-watt warm, four 10-watt neutral and introduced a crutch down the brightness.
- Neutral white LEDs - nasty, unpleasant to the eye.
- I can not think of emulation clamping keys on a computer keyboard. Because of this, the light changes in spurts, because delay - fixed.
- Remote control periodically proglyuchivaet, namely not caught by the receiver, therefore, when he hath lighted indicator on the remote - not a guarantee of signal delivery. For this purpose it was necessary to introduce an indicator on the chandelier
- Massive radiator for two 20-watt LEDs - was not enough, or they are working in extreme mode. Tomorrow I measure the currents and try to put a resistor.
- Courtesy light - complete crap, because it shows all the snot on the wires. I plan to order the matte acrylic, and make diffused white light.
- Did not find the market KREN5A (unbelievable but true), because of this, for Arduin had to put extra. power supply, but I wanted to feed her from the driver.
- Snot - it is not good, Arduino too. Etched fee for atmegi, come programmer - get rid of excess mucus.
Thanks for reading until the end. H4> Are you interested in the fact that I posted another article with an improved chandelier?
| yes |
| not Voted 242 people. 40 people abstained. Only registered users can vote in polls. Sign , please. Source: habrahabr.ru/post/247151/
Best pictures from the telescope "Hubble" (Part Two)
IBM is working with Nvidia to create a new generation of supercomputers
|