Don't have a picture of my actual breadboard at the moment but I recreated this tinkercad I made onto an actual breadboard and it won't even turn on. In the tinkercad, it also doesn't work because when I turn it on it won't light up at all or sometimes it will light up but only show the number 8? Information: The two seven segment displays are common anode and the goal of this project is for it to count up from 0 and display it on the 7 segment displays.
Any advice for how to make this work on the tinkercad (I can just apply the same logic to making it on a breadboard if I fix the tinkercad)!
Heres my code for reference:
// blinking lights at different rates using the timer module
// -------------------------------------------------------------------------------------------
// hook into timer0 that's already setup for the millis function to give 1ms timer interrupts
// on real hardware you could use the Timer1 library but it's not avaibale in Tinkercad.
class TimerZero
{
public:
void initialize()
{
// compare interrupt somewhere in the middle of the count
OCR0A = 0xAF;
}
// Interrupt Function
void attachInterrupt(void (*isr)()) __attribute__((always_inline)) {
isrCallback = isr;
TIMSK0 |= _BV(OCIE0A);
}
static void (*isrCallback)();
};
TimerZero Timer0; // preinstatiate
void (*TimerZero::isrCallback)() = NULL;
ISR(TIMER0_COMPA_vect)
{
Timer0.isrCallback();
}
// -------------------------------------------------------------------------------------------
// pin definitions
#define SEGMENT_A_PIN 9
#define SEGMENT_B_PIN 10
#define SEGMENT_C_PIN 4
#define SEGMENT_D_PIN 5
#define SEGMENT_E_PIN 6
#define SEGMENT_F_PIN 8
#define SEGMENT_G_PIN 7
#define DIGIT_1_PIN 2
#define DIGIT_2_PIN 3
#define NUM_SEGMENTS 7
#define NUM_DIGITS 2
#define NUM_SYMBOLS 10
// counter definitions, in milliseconds
const uint16_t MUTIPLEX_COUNT = 10; // 20ms multiplex rate
const uint16_t SLOW_COUNT = 400; // 5 updates a second
const uint8_t digits[NUM_DIGITS] = {DIGIT_1_PIN, DIGIT_2_PIN};
const uint8_t segments[NUM_SEGMENTS] = {SEGMENT_A_PIN, SEGMENT_B_PIN, SEGMENT_C_PIN, SEGMENT_D_PIN, SEGMENT_E_PIN, SEGMENT_F_PIN, SEGMENT_G_PIN };
const uint8_t symbols[NUM_SYMBOLS][NUM_SEGMENTS] = {
{HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, LOW}, // 0
{LOW, HIGH, HIGH, LOW, LOW, LOW, LOW}, // 1
{HIGH, HIGH, LOW, HIGH, HIGH, LOW, HIGH}, // 2
{HIGH, HIGH, HIGH, HIGH, LOW, LOW, HIGH}, // 3
{LOW, HIGH, HIGH, LOW, LOW, HIGH, HIGH}, // 4
{HIGH, LOW, HIGH, HIGH, LOW, HIGH, HIGH}, // 5
{HIGH, LOW, HIGH, HIGH, HIGH, HIGH, HIGH}, // 6
{HIGH, HIGH, HIGH, LOW, LOW, LOW, LOW}, // 7
{HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH}, // 8
{HIGH, HIGH, HIGH, HIGH, LOW, HIGH, HIGH} // 9
};
// initialise variables
uint16_t mutiplexCounter = MUTIPLEX_COUNT;
uint16_t slowCounter = SLOW_COUNT;
uint8_t currentDigit = 1;
uint8_t digitNum[NUM_DIGITS] = {0,0};
// timer callback function
void timerCallback(void)
{
// handle the 1 second heartbeat counter
if (!--mutiplexCounter)
{
// switch off current digit
digitalWrite(digits[currentDigit], LOW);
//
if(++currentDigit > NUM_DIGITS-1)
currentDigit = 0;
for (uint8_t segment=0; segment < NUM_SEGMENTS; segment++)
{
digitalWrite(segments[segment], symbols[digitNum[currentDigit]][segment]);
}
// switch on new digit
digitalWrite(digits[currentDigit], HIGH);
// reload heartbeat counter
mutiplexCounter = MUTIPLEX_COUNT;
}
if (!--slowCounter)
{
digitNum[0]++;
if (digitNum[0] > NUM_SYMBOLS-1)
{
digitNum[0] = 0;
digitNum[1]++;
if (digitNum[1] > NUM_SYMBOLS-1)
digitNum[1]=0;
}
// reload the slow counter
slowCounter = SLOW_COUNT;
}
}
void setup()
{
// configure pins
for (uint8_t segment=0; segment < NUM_SEGMENTS; segment++)
{
pinMode(segments[segment], OUTPUT);
}
pinMode(DIGIT_1_PIN, OUTPUT);
pinMode(DIGIT_2_PIN, OUTPUT);
// set up the timer
Timer0.initialize(); // 1 millisecond timer rate
// each interrupt, call our function
Timer0.attachInterrupt(timerCallback);
}
void loop()
{
// all the work is done on the timer callback
}
Project Image: