I begin testing out my seven-segment display. I tested it out by using a power supply and a variable resistor.
Project Snapshot
I made this project to continue learning about shift registers. I used a seven-segment display to make it more challenging. I made two programs: counting up and a random number generator.
The materials I used are:
Code
#include <Arduino.h>
// 1. Tell the computer what pins the shift register is on
const int latchPin = 12;
const int clockPin = 13;
const int dataPin = 11;
int time = 400;
const byte digitMap[] = {
0b11110110, // 0
0b10000100, // 1
0b01101110, // 2
0b11001110, // 3
0b10011100, // 4
0b11011010, // 5
0b11111010, // 6
0b10000110, // 7
0b11111110, // 8
0b11011110 // 9
};
void setup() {
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
delay(2000);
}
void displayNumber(int myNumber) {
digitalWrite(latchPin, LOW); // 1. Open the shifter gate
shiftOut(dataPin, clockPin, MSBFIRST, digitMap[myNumber]); // 2. Push the raw bits out
digitalWrite(latchPin, HIGH); // 3. Close the gate to update the screen
}
void loop() {
for (int i = 0; i < 10; i++) {
displayNumber(i);
delay(time);
}
}
#include <Arduino.h>
// 1. Tell the computer what pins the shift register is on
const int latchPin = 12;
const int clockPin = 13;
const int dataPin = 11;
const int buttonPin = 9;
int time = 400;
const byte digitMap[] = {
0b11110110, // 0
0b10000100, // 1
0b01101110, // 2
0b11001110, // 3
0b10011100, // 4
0b11011010, // 5
0b11111010, // 6
0b10000110, // 7
0b11111110, // 8
0b11011110, // 9
0b00000000 // 10
};
void setup() {
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
}
void displayNumber(int myNumber) {
digitalWrite(latchPin, LOW); // 1. Open the shifter gate
shiftOut(dataPin, clockPin, MSBFIRST, digitMap[myNumber]); // 2. Push the raw bits out
digitalWrite(latchPin, HIGH); // 3. Close the gate to update the screen
}
void loop() {
if (digitalRead(buttonPin) == LOW) {
displayNumber(random(0, 10));
delay(80);
}
}
I begin testing out my seven-segment display. I tested it out by using a power supply and a variable resistor.
I made sure every single segment works.
Then I wired the seven-segment display to my microcontroller and shift register.
I then programmed a simple count up to nine program.
Then I began to make a random number generator with a display. I first added a button and made it turn on the number 9.
Then I added a random aspect to make it a true random generator. Instead of having the number appear only when the button is pressed,the button held its state while waiting for button clicks.