Components and supplies
Various electronic components: resistors, capacitors, transistors, MOSFET, optocouplers, pushbuttons, IC socket 8 DIP, raw PCB, wires
MT3608 DC DC Step Up Adjustable Converter Booster Power Supply Module Output 2A
ATtiny85
JST Plug (Optional)
2S Lithium ion Battery Charger Module
2x Lithium Battery 18650
Micro USB plug female
Tools and machines
Various tools: drill, grinder, saw
Project description
Code
Arduino Scatch: Multifunktional_working_LED_Light_v1.4_Final_ATtiny85.ino
arduino
1/*+-------------------------------------------------------------------------------------------------------------------------------+ 2 | Multifunctional working LED-lamp | 3 +-------------------------------------------------------------------------------------------------------------------------------+ 4 | Description | 5 | =========== | 6 | This is a small scatch for a high power LED. The brightness is controlled with the help of the One Button-Lib. | 7 | The following functions are available to make the LED brighter with "SW_H" or darker with "SW_L": | 8 | Simple click, double-click, long click. | 9 | | 10 | The second function "Display_ON" with an additional key "SW_D" switches on an output for a | 11 | multifunctional display for 30 seconds. | 12 | Testet on a ATtiny85 @ 1 MHz (internal) with bootloader and without Bootloader, works well. | 13 | The Sketch uses 2380 bytes (29%) flash space. | 14 | The Serial communication monitoring is only for debugging on a other devices and it do not work with the tiny85 | 15 | It musst be disabled bevore you upload the Code! | 16 | | 17 +-------------------------------------------------------------------------------------------------------------------------------+ 18 | THE FUNCTIONS: | 19 | ============== | 20 | .attachClick: SW_H / SW_L gradually lighter or darker. | 21 | .attachDoubleClick: SW_H / SW_L very light or dark. | 22 | .attachDuringLongPress: SW_H / SW_L dimming via PWM. | 23 | Display_ON: SW_D for 30 seconds. | 24 | | 25 +-------------------------------------------------------------------------------------------------------------------------------+ 26 | WIRING: | 27 | ======= | 28 | ATtiny85 | 29 | __ __ | 30 | RST -|1 \\/ 8|- VCC | 31 | SW_L -|2 7|- SW_D | 32 | SW_H -|3 6|- DISPLAY | 33 | GND -|4____5|- LED | 34 | | 35 +-------------------------------------------------------------------------------------------------------------------------------+ 36 | SOFTWARE INFO | 37 | ============= | 38 | Version: 1.4_Final | 39 | Writen Date: 16-05.2018 | 40 | Autor: Zislaw Kromski kromski@gmx.ch | 41 | Software Info: Arduino IDE_v_1.8.5 https://www.arduino.cc/en/Main/Software | 42 | OneButton.h_v_1.2.0 http://www.mathertel.de/Arduino/OneButtonLibrary.aspx | 43 | | 44 +-------------------------------------------------------------------------------------------------------------------------------+ 45 */ 46 47#include "OneButton.h" 48 49#define LED 0 // Dimmable High power LED over MOSFET driver "attach to a PWM Pin". 50#define DISPLAY 1 // Output-ON signal for the "Multifunktional Time Display" enabled with SW_D for 30 seconds. 51#define AMOUNT 51 // Stepped (255/51 = 5 steps) increment/decrement brightness. 52#define AMOUNTDIMM 10 // Running (255/10 = +/-25 steps)increment/decrement brightness. 53#define SW_D 2 // Button for Display. 54byte brightness = 0; // Variable brightness Set to 0. 55unsigned long currentMillis; // current time stamp. 56unsigned long lastTime =0; // Preview time stamp. 57const long onTime = 30000; // On time for Display Output "30sec". 58bool SW_D_state; // Flag for the button status. 59bool displayOn = false; // Flag for the display status. 60 61OneButton SW_H(4, true); // Setup a new OneButton Object for (SW1)true=internal PullUp Resistor. 62OneButton SW_L(3, true); // Setup a new OneButton Object for (SW2)true=internal PullUp Resistor. 63 64 65void setup() { 66 67 //Serial.begin(9600); // Serial monitoring for debugging only. 68 //Serial.println("Start"); // ... 69 70 pinMode(SW_D, INPUT_PULLUP); // Display_ON button as INPUT enable PULLUP. 71 pinMode(DISPLAY, OUTPUT); // Display output as OUTPUT. 72 digitalWrite(DISPLAY, LOW); // Set Display output to HIGH. 73 74 SW_H.attachClick(click_SW_H); // link the button "SW_H" to the funktion (amount_high)PWM +AMOUNT. 75 //SW_H.setClickTicks(300); // Set millisec after single click is assumed (For customization only). 76 //setDebounceTicks(100) // Set millisec after safe click is assumed (For customization only). 77 SW_H.attachDoubleClick(doubleclick_SW_H); // link the button "SW_H" to the funktion (Full) PWM =255. 78 SW_H.attachDuringLongPress(dimm_SW_H); // link the button "SW_H" to the funktion (amount_dimm_high)PWM +AMOUNTDIMM. 79 //SW_H.setPressTicks(100); // Set millisec after press is assumed (For customization only). 80 81 SW_L.attachClick(click_SW_L); // link the button "SW_L" to the funktion (amount_low)PWM -AMOUNT. 82 SW_L.attachDoubleClick(doubleclick_SW_L); // link the button "SW_L" to the funktion (Off)/PWM =0. 83 SW_L.attachDuringLongPress(dimm_SW_L); // link the button "SW_L" to the funktion (amount_dimm_low)PWM -AMOUNTDIMM. 84 85 analogWrite(0, 50); // Whenn Device ON, turn LED on. 86 } 87 88void loop() { 89//----------Funktions for Display_ON---------// 90 SW_D_state = digitalRead(SW_D); // Status variable for SW_D. 91 currentMillis = millis(); // Variable current time takes timestamp. 92 if(!displayOn && SW_D_state == LOW){ // Query: If SW_D is pressed and display is not on. 93 lastTime = currentMillis; // Last time update. 94 displayOn = true; // Change display status to on. 95 digitalWrite (DISPLAY, HIGH); // Turn Display on. 96 //Serial.print("Display ON "); // ... 97 //Serial.println(millis()); // ... 98 } 99 if(displayOn && currentMillis -lastTime >onTime){ // Only if display is on and past time greater than onTime. 100 displayOn = false; // Change display status to off. 101 digitalWrite(DISPLAY, LOW); // Turn Display off. 102 //Serial.print("Diaplay OFF "); // ... 103 //Serial.println(currentMillis); // ... 104 } 105 106 SW_H.tick(); // keep watching the push buttons. 107 SW_L.tick(); // keep watching the push buttons. 108 delay(10); // Short break is recommended by the OneButton lib. 109} 110 111//----------Funktions for brighter-----------// 112 113void click_SW_H(){ // Function one click for big steps. 114 if(brightness >204){ // Query the variable for balancing so that LED gets very light in the last step (fifth click). 115 brightness =255; // Updating the variable 116 analogWrite(LED, brightness); // Analog write the PWM values. 117 //Serial.print("click_SW_H PWM = "); // ... 118 //Serial.println(brightness); // ... 119 } 120 121 if(brightness <=204){ // Query the variable if PWM less than 204. 122 brightness = brightness +AMOUNT; // If yes, then Updating the variable and increase in big steps (+ AMOUNT). 123 analogWrite(LED, brightness); // Analog write the PWM values. 124 //Serial.print("click_SW_H PWM = "); // ... 125 //Serial.println(brightness); // ... 126 delay(400); // Waiting time. 127 } 128} 129void doubleclick_SW_H(){ // Function double-click for very bright. 130 analogWrite(LED, 255); // Analog write the PWM values. 131 brightness = 255; // Updating the variable. 132 //Serial.print("doubleclick_SW_H PWM = "); // ... 133 //Serial.println("255"); // ... 134} 135void dimm_SW_H(){ // Function Keep button for slow dimming. 136 if(brightness >245){ // Query the variable for balancing so that LED gets very light in the last step (25th click). 137 brightness = 255; // Updating the variable. 138 analogWrite(LED, brightness); // Analog write the PWM values. 139 //Serial.print("dimm_SW_H PWM = "); // ... 140 //Serial.println(brightness); // ... 141 } 142 143 if(brightness <=245){ // Query the variable if PWM less than 245. 144 brightness = brightness +AMOUNTDIMM; // If yes, then Updating the variable and increase in small steps (+ AMOUNTDIMM). 145 analogWrite(LED, brightness); // Analog write the PWM values. 146 //Serial.print("dimm_SW_H PWM = "); // ... 147 //Serial.println(brightness); // ... 148 delay(400); // Waiting time for the speed of dimming. 149 } 150} 151 152//----------Funktions for darker-----------// 153 154void click_SW_L(){ // Function one click for big steps. 155 if(brightness <51){ // Query the variable for balancing so that LED gets very dark in the last step (fifth click). 156 brightness = 0; // Updating the variable 157 analogWrite(LED, brightness); // Analog write the PWM values. 158 //Serial.print("click_SW_L PWM = "); // ... 159 //Serial.println(brightness); // ... 160 } 161 162 if(brightness >=51){ // Query the variable if PWM greater than 204. 163 brightness = brightness -AMOUNT; // If yes, then Updating the variable and decrease in big steps (- AMOUNT). 164 analogWrite(LED, brightness); // Analog write the PWM values. 165 //Serial.print("click_SW_L PWM = "); // ... 166 //Serial.println(brightness); // ... 167 delay(400); // Waiting time. 168 } 169} 170 171void doubleclick_SW_L(){ // Function double-click for very dark. 172 analogWrite(LED, 0); // Analog write the PWM values. 173 brightness = 0; // Updating the variable. 174 //Serial.print("doubleclick_SW_L PWM = "); // ... 175 //Serial.println("0"); // ... 176} 177void dimm_SW_L(){ // Function Keep button for slow dimming. 178 if(brightness <10){ // Query the variable for balancing so that LED gets very dark in the last step (25th click). 179 brightness = 0; // Updating the variable. 180 analogWrite(LED, brightness); // Analog write the PWM values. 181 //Serial.print("dimm_SW_L PWM = "); // ... 182 //Serial.println("0"); // ... 183 } 184 185 if(brightness >=10){ // Query the variable if PWM greater than 10. 186 brightness = brightness -AMOUNTDIMM; // If yes, then Updating the variable and decrease in small steps (- AMOUNTDIMM). 187 analogWrite(LED, brightness); // Analog write the PWM values. 188 //Serial.print("dimm_SW_L PWM = "); // ... 189 //Serial.println(brightness); // ... 190 delay(400); // Waiting time for the speed of dimming. 191 } 192} 193 194// END SKETCH 195
Downloadable files
Multifunctional Working lighting LED_v3.1b.sch
Multifunctional Working lighting LED_v3.1b.sch
Multifunctional Working lighting LED_v3.1b.brd
Multifunctional Working lighting LED_v3.1b.brd
Multifunctional Working lighting LED_v3.1b.brd
Multifunctional Working lighting LED_v3.1b.brd
Multifunctional Working lighting LED_v3.1b.sch
Multifunctional Working lighting LED_v3.1b.sch
Comments
Only logged in users can leave comments