One step closer to a functional Moscow Time display. The plan is to use an ESP8266 so therefore I use a shift register even though the Arduino I am testing on now has enough outputs

Reply to this note

Please Login to reply.

Discussion

Does markdown "code" work? let's see 👇

``#define one_pin 4

#define ten_pin 5

#define hundred_pin 6

#define thousand_pin 7

int latch_pin = 8;

int clock_pin = 12;

int data_pin = 11;

byte common_cathodes[] = {one_pin, ten_pin, hundred_pin, thousand_pin};

// Array with the decimal value for the numbers that will be shown in the bubble display

const int num_array[] = {

243, // 0

66, // 1

217, // 2

218, // 3

106, // 4

186, // 5

59, // 6

194, // 7

251, // 8

234 // 9

};

const int display_delay = 1; // Delay

void setup() {

pinMode(latch_pin, OUTPUT);

pinMode(clock_pin, OUTPUT);

pinMode(data_pin, OUTPUT);

for (int i = 0; i < 4; i++) {

pinMode(common_cathodes[i], OUTPUT);

digitalWrite(common_cathodes[i], HIGH);

}

}

void loop() {

display(1337);

}

void display(int num) {

// Display a number on the bubble display

int one_num = num % 10;

int ten_num = (num / 10) % 10;

int hundred_num = (num / 100) % 10;

int thousand_num = (num / 1000) % 10;

int num_places[] = {one_num, ten_num, hundred_num, thousand_num};

for (int i = 0; i < 4; i++) {

digitalWrite(latch_pin, LOW); // Latch pin LOW

shiftOut(data_pin, clock_pin, LSBFIRST, num_array[num_places[i]]);

digitalWrite(common_cathodes[i], LOW); // Set the cathode to LOW to display the correct number

digitalWrite(latch_pin, HIGH); // Latch pin HIGH

delay(display_delay);

digitalWrite(common_cathodes[i], HIGH);

}

}``