My background is more Mechanics and educated to be a Toolmaker. After that, I did Installation Technology and for this, you need some basic understanding of electronics that manages the installation. But this is only very basic and crude, it doesn't dive very deep into the details and only serves the purpose of general troubleshooting if the installation fails to power up to know at which module to look. Then after that, I worked for 10 years in the IT branch as SysAdmin in the XP en W7 era also learning some Visual Basic Scripting to automate some administrative tasks, so I can kinda figure out what LUA basically does. So I tasted a bit of all these trades and I'm far from an expert in any of them, all that is generally not used on a daily basis got a bit rusty, but learned enough to get the most important part of the picture to build things and fix things affiliated.
This little project is born out of a completely different hobby of mine and that is building Aquariums and Terrariums. One is building Micro Terrariums like the one below.
This runs with 3 LEDs on the mains with a PSU en a timer switch. And a friend gave me the idea that it would be awesome to build one on battery power... I agreed and thought it would be a nice challenge to realize this. This friend gave me his Anker 30.000mAh power bank to do some experimenting. So on I quickly found Arduino and the ATTiny and the low-power consumption applications that can be built with it.
Anyway, in my research, I found out that to get the most out of this power bank I need to ditch all bells and whistles regarding relays, RTC modules, NTP and Wifi connections, etc. all requiring too much power. And simply use the ATTiny internal Millis time base to switch a couple of bright white LEDs on and off for 12 hours in a continuous loop. Time inaccuracy is rather irrelevant since it gets a hard reset about every +/- 30 days when replacing the battery with a freshly charged one.
But it wasn't as easy as I hoped it to be with the darn shut down feature in the power bank throwing salt in the soup. Making the circuit a tad more complex and requiring a tad more insight into the working of the components required.
That's where you guys came in, giving me a heads-up with some great answers to my question with a tad extra to make it running a bit more smoothly than it did... SO THANKS! A bunch for that...
Anyway, I simply used 2 Blink without delays using Millis example snippets I found on the net combined them into one and it seems to run pretty smooth. Already for 20 days now with the power bank still over 50% charged. I bet i can be done even more smoothly than this but for the noob I am, I'm pretty satisfied with the results for now... My ATTiny Terrarium will be shining on battery power next month... What's the purpose of all this? Whatever you can make out of it, placing it where ever you want without the need of a mains socket nearby. Take it for a walk or take it to bed and cuddle it, options are numerous. 8)
This is the code I used.
#define TWELVE_HRS 43200000UL
#define ONE_MIN_FIFTY 110000L
#define ONE_SEC 1000L
const int LEDpin = 1;
const long onDuration = ONE_SEC;
const long offDuration = ONE_MIN_FIFTY;
int LEDState =HIGH;
long rememberTime=0;
unsigned long interval=TWELVE_HRS;
unsigned long previousMillis=0;
bool ledState = true;
void setup() {
pinMode(3, OUTPUT);
digitalWrite(3, ledState);
pinMode(LEDpin,OUTPUT);
digitalWrite(LEDpin,LEDState);
}
void loop() {
unsigned long currentMillis = millis();
if ((unsigned long)(currentMillis - previousMillis) >= interval) {
ledState = !ledState;
digitalWrite(3, ledState);
previousMillis = millis();
}
{
if( LEDState ==HIGH )
{
if( (millis()- rememberTime) >= onDuration){
LEDState = LOW;
rememberTime=millis();
}
}
else
{
if( (millis()- rememberTime) >= offDuration){
LEDState =HIGH;
rememberTime=millis();
}
}
}
digitalWrite(LEDpin,LEDState);
}
Thanks again for the helping hand... I'll be building more of these ATTiny Terrariums in the future... Thus I might have some more questions by then...