I've thrown together a basic clock using an Arduino, a DS1307, two 74HC595s and some common anode segment LEDs. The circuit is based on this (minus the temp sensor):
And here's the digispark-specific code:
#include <Time.h> //Time Library
#include <TinyRTClib.h> //Digispark version of RTC Library
#include <TinyWireM.h> //Digispark version of Wire library
RTC_DS1307 RTC;
int clockPin = 3; // connected in the pin 11 of 74HC595 (Clock)
int latchPin = 4; // connected in the pin 12 of 74HC595 (Latch)
int dataPin = 1; // connected in the pin 14 of 74HC595 (Data)
int hora, minuto;
int unidadeHora, unidadeMinuto, dezenaHora, dezenaMinuto;
//Digits Matrix - 0 a 9
byte num[] = {
B01111110, // Zero
B00110000, // One
B01101101, // Two
B01111001, // Three
B00110011, // Four
B01011011, // Five
B01011111, // Six
B01110000, // Seven
B01111111, // Eight
B01111011, // Nine
};
void setup() {
pinMode(latchPin, OUTPUT); // Define the 3 digital pins as output
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
TinyWireM.begin();
RTC.begin();
}
void loop() {
DateTime now = RTC.now(); // Get the RTC info
hora = now.hour();
minuto = now.minute();
unidadeHora = hora % 10;
dezenaHora = hora / 10;
unidadeMinuto = minuto % 10;
dezenaMinuto = minuto / 10;
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 8); //Set DISPLAY 1 (top view from left to right)
shiftOut(dataPin, clockPin, LSBFIRST, ~num[dezenaHora]); //Set the Hour (ten)
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 4); //Set DISPLAY 2
shiftOut(dataPin, clockPin, LSBFIRST, ~num[unidadeHora]); //Set the Hour (unit)
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 2); //Set DISPLAY 3
shiftOut(dataPin, clockPin, LSBFIRST, ~num[dezenaMinuto]); //Set the Minute (ten)
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 1); //Set DISPLAY 4
shiftOut(dataPin, clockPin, LSBFIRST, ~num[unidadeMinuto]); //Set the Minute (unit)
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 8); //Set LED of dots
shiftOut(dataPin, clockPin, LSBFIRST, ~B10000000); //Set LEDs of double dots
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 1); //Set DISPLAY 4
shiftOut(dataPin, clockPin, LSBFIRST, 255); //Reset the DISPLAY 4 (to avoid some flicking)
digitalWrite(latchPin, HIGH);
}
So far everything works, as long as I supply power through the digispark's USB port.
But I also want to use a step-up converter, taking power from a 18650 cell and bumping it to 5v. When I use this converter, two of the four segment LEDs flickers, as if the LEDs are grounding out somewhere (segments that should be blank glow dimly).
Of course, you'd think the step-up converter was at fault. But when I replace the Digispark with a Nano (and swap the required libraries), then everything works fine running on battery power - it's just the digispark that's not happy. So I tried a second digispark, in case there's a flaw in the board, and I have the same flickering symptoms.
Anyone got any ideas what's causing this?