Attachment 'LED_Dimmer.ino'

Download

   1 /*
   2  Programm: LED_Dimmer.ino
   3  Ausgang: Pulsweitenmodulation für FET schalten nach 0 V
   4           Frequenz 500 Hz, linear dimmen von Wert 3 nach 255 und zurück
   5           Rampenzeit 30 min, im Test (JP2 Brücke) 5 sek + 2 sek Pause bei Apin 3 (pin 2)
   6           
   7  Eingang A: +5 V Schaltsignal von Zeitschaltuhr, +5 V = EIN
   8  ODER
   9  Eingang B: 30 sek Kontakt nach 0 V für Einschalten
  10             30 sek Kontakt nach 0 V für Ausschalten
  11             von Jarolift Multi time Control (original für Rollladen)
  12             
  13  Prozessor: Atmel ATtiny85 (Flash-ROM 8 KB, RAM 256 Byte, EEPROM 256 Byte
  14  Arduino: ATtiny85 @ 1 MHz (internal oscillator; BOD disabled) 
  15  Software: http://arduino.cc/en/Reference/HomePage
  16  
  17  2013-02-20 Rudolf Reuter
  18  Copyright: GPL2
  19  
  20  */
  21  
  22 // it needs update of hardware/tiny/core/tiny/wiring_digital.c function pinMode()
  23 #ifndef INPUT_PULLUP
  24 #define INPUT_PULLUP 2
  25 #endif
  26 
  27 //#define debug
  28 
  29 const int del_2s = 10;       // Ramp = 2,5 s
  30 const int del_30min = 7142;  // Ramp = 7,142 * 255 = 1836 s = 30 min
  31 
  32 const int PinDimOff = 0;    // dimm LED OFF
  33 const int PinDimOn  = 1;    // dimm LED ON
  34 const int PinTest   = 2;    // 0 V = Test ON
  35 const int PinLedOn  = 3;    // +5 V = LED ON
  36 const int PinLED    = 4;    // LED connected to digital pin 4 (tiny 3)
  37 
  38 int LedOnA = 0;  // save LED ON state A
  39 int LedOnB = 0;  // save LED ON state B
  40 int del_incr = del_30min;
  41 
  42 void setup()  { 
  43     pinMode( PinDimOff, INPUT_PULLUP ); 
  44     pinMode( PinDimOn, INPUT_PULLUP ); 
  45     pinMode( PinTest, INPUT_PULLUP );
  46     pinMode( PinLedOn, INPUT );
  47     // show Power On Reset puls
  48     analogWrite(PinLED, 255); 
  49     delay(500);
  50     analogWrite(PinLED, 0); 
  51     delay(500);
  52 } 
  53 
  54 void test_loop() {
  55     // fade in from min to max in increments:
  56     for(int fadeValue = 3 ; fadeValue <= 255; fadeValue +=1) { 
  57         // sets the value (range from 3 to 255):
  58         analogWrite(PinLED, fadeValue);         
  59         // wait for 30 milliseconds to see the dimming effect    
  60         delay(10);   // set 7200 for 30 min fade                         
  61     } 
  62 
  63     // fade out from max to min in increments:
  64     for(int fadeValue = 255 ; fadeValue >= 3; fadeValue -=1) { 
  65         // sets the value (range from 3 to 255):
  66         analogWrite(PinLED, fadeValue);         
  67         // wait for 30 milliseconds to see the dimming effect    
  68         delay(10);                            
  69     } 
  70     delay(2000);  // see minimum better
  71 }
  72 
  73 void LedDimOn() {
  74     // fade in from min to max in increments:
  75     for(int fadeValue = 3 ; fadeValue <= 255; fadeValue +=1) { 
  76         // sets the value (range from 3 to 255):
  77         analogWrite(PinLED, fadeValue);  
  78         if ( digitalRead(PinTest) == 0 ) del_incr = del_2s;         
  79         delay(del_incr);                           
  80     } 
  81 }
  82 
  83 void LedDimOff() {
  84    // fade out from max to min in increments:
  85     for(int fadeValue = 255 ; fadeValue >= 3; fadeValue -=1) { 
  86         // sets the value (range from 3 to 255):
  87         analogWrite(PinLED, fadeValue);
  88         if ( digitalRead(PinTest) == 0 ) del_incr = del_2s;    
  89         delay(del_incr);                            
  90     } 
  91 }
  92 
  93 void loop()  { 
  94     void test_loop();
  95     void LedDinOn();
  96     void LedDimOff();
  97   
  98     #ifdef debug
  99         while ( digitalRead(PinTest) == 0 ) test_loop();
 100     #endif
 101   
 102     // check for Input A = +5 V
 103     if ( digitalRead(PinLedOn) > 0 && (LedOnA == 0) ) {
 104         LedDimOn();
 105         LedOnA = 1;
 106     }
 107  
 108     // check for Input A = 0 V
 109     if ( (digitalRead(PinLedOn) == 0) && (LedOnA > 0) ) {
 110         LedDimOff();
 111         LedOnA = 0;
 112     }
 113  
 114      // check for Input B, LED dim ON
 115     if ( digitalRead(PinDimOn) == 0 && (LedOnB == 0) ) {
 116         LedDimOn();
 117         LedOnB = 1;
 118     }
 119    
 120     // check for Input B, LED dim OFF
 121    if ( digitalRead(PinDimOff) == 0  && (LedOnB > 0) ) {
 122        LedDimOff();
 123        LedOnB = 0;
 124    }
 125 }

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2014-01-23 20:27:00, 79.8 KB) [[attachment:LED_Dimmer.brd]]
  • [get | view] (2014-01-23 20:27:00, 64.3 KB) [[attachment:LED_Dimmer.eps]]
  • [get | view] (2013-05-08 04:53:00, 3.8 KB) [[attachment:LED_Dimmer.ino]]
  • [get | view] (2014-01-23 19:45:00, 489.5 KB) [[attachment:LED_Dimmer.sch]]
  • [get | view] (2013-05-08 04:53:00, 123.7 KB) [[attachment:LED_DimmerP_RS_DSC04153.jpg]]
  • [get | view] (2013-05-08 04:53:00, 112.8 KB) [[attachment:LED_DimmerP_VS_DSC04152.jpg]]
  • [get | view] (2013-05-08 04:53:00, 29.7 KB) [[attachment:LED_DimmerP_sch.pdf]]
  • [get | view] (2013-05-08 04:53:00, 235.8 KB) [[attachment:LED_DimmerP_sch.png]]
  • [get | view] (2014-01-23 19:29:00, 93.2 KB) [[attachment:LED_Dimmer_PCB_LS_DSC05078.jpg]]
  • [get | view] (2014-01-23 19:29:00, 77.6 KB) [[attachment:LED_Dimmer_PCB_US_DSC05077.jpg]]
  • [get | view] (2014-01-30 19:19:00, 38.9 KB) [[attachment:LED_Dimmer_sch.pdf]]
  • [get | view] (2014-01-30 19:20:00, 81.7 KB) [[attachment:LED_Dimmer_sch.png]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.