Things were really starting to look up for Morgan State Company. The high-tech credit card has been nicknamed "microcontroller super card" because of all the great improvement ideas. Morgan State Company has pitched my card design to the company I suggested and have received a lot of positive feedback. Several of the companies have requested a demonstration, now the pressure is on to produce samples that can be shown to potential customers. The company already has the hardware for the 7-segment display microcontroller super card but no software.
Because I did such a great job completing the LED software for my mentor I have been selected to write the code for the 7-segment display. In two weeks my mentor has several meetings scheduled with some major corporations to demonstrate this design. It is very important I meet this deadline.
Syntax/Instructions Used
digitalWrite(PIN, ); - sends digital value to PIN
pinMode(PIN, MODE); - assigns I/O operation/MODE to PIN
delay(time); - delays by time in milliseconds
void setup(){} - operation to be executed only once
void loop(){} - operation to be executed repeatedly
Design
void setup()
{
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
}
void loop()
{
//Number 0
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
delay(1000);
//Number 1
digitalWrite(1, HIGH);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
delay(1000);
//Number 2
digitalWrite(1, LOW);
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
delay(1000);
//Number 3
digitalWrite(1, HIGH);
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
delay(1000);
//Number 4
digitalWrite(4, LOW);
digitalWrite(3, HIGH);
digitalWrite(2, LOW);
digitalWrite(1, LOW);
delay(1000);
//Number 5
digitalWrite(4, LOW);
digitalWrite(3, HIGH);
digitalWrite(2, LOW);
digitalWrite(1, HIGH);
delay(1000);
//Number 6
digitalWrite(4, LOW);
digitalWrite(3, HIGH);
digitalWrite(2, HIGH);
digitalWrite(1, LOW);
delay(1000);
//Number 7
digitalWrite(4, LOW);
digitalWrite(3, HIGH);
digitalWrite(2, HIGH);
digitalWrite(1, HIGH);
delay(1000);
//Number 8
digitalWrite(4, HIGH);
digitalWrite(3, LOW);
digitalWrite(2, LOW);
digitalWrite(1, LOW);
delay(1000);
//Number 9
digitalWrite(4, HIGH);
digitalWrite(3, LOW);
digitalWrite(2, LOW);
digitalWrite(1, HIGH);
delay(1000);
}
On the Circuit Board
Equipments Used: 7-Segment display, decoder driver, and dual inline resistor
Fig: Counter Circuit Schematic
INPUTS | PIN ON ARDUINO BOARD |
A | Pin 1 |
B | Pin 2 |
C | Pin 3 |
D | Pin 4 |
Vcc | Pin 13 |
Table: Pin Configuration
BCD inputs | segment outputs | display | |||||||||
D | C | B | A | a | b | c | d | e | f | g | |
0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 1 |
0 | 0 | 1 | 0 | 1 | 1 | 0 | 1 | 1 | 0 | 1 | 2 |
0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 | 3 |
0 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 1 | 4 |
0 | 1 | 0 | 1 | 1 | 0 | 1 | 1 | 0 | 1 | 1 | 5 |
0 | 1 | 1 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 6 |
0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 7 |
1 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 8 |
1 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | 1 | 1 | 9 |
Table: BCD Decoder Outputs
Demos/Results
I demonstrated my knowledge and approach during the demo of the lab. I showed how to first verify the code, and then upload on to the arduino board. I then wrote a code for the counter to go from 0 to 9 using a time delay of 1000ms (1s) after each digit. I ran through an error at some point related to the port I used but after troubleshooting I changed ports from the tools menu. I was able to get the seven segment display counting from 0 to 9 again. I put a video of this on YouTube.
I was also able to dial my telephone number making the digit and LEDs blink that number of times using the code below. I also put a demo of this on YouTube.
My Number: (395)602-0044
int x = 0;
void setup()
{
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(13, OUTPUT);
pinMode(7, OUTPUT);
}
void loop()
{
//Number 4
for(x=0; x<4; x++)
{
digitalWrite(13, HIGH);
digitalWrite(4, LOW);
digitalWrite(3, HIGH);
digitalWrite(2, LOW);
digitalWrite(1, LOW);
digitalWrite(7, HIGH);
delay(300);
digitalWrite(7, LOW);
digitalWrite(13, LOW);
delay(300);
}
delay(1000);
//Number 4
for(x=0; x<4; x++)
{
digitalWrite(13, HIGH);
digitalWrite(4, LOW);
digitalWrite(3, HIGH);
digitalWrite(2, LOW);
digitalWrite(1, LOW);
digitalWrite(7, HIGH);
delay(300);
digitalWrite(7, LOW);
digitalWrite(13, LOW);
delay(300);
}
delay(1000);
//Number 3
for(x=0; x<3; x++)
{
digitalWrite(13, HIGH);
digitalWrite(1, HIGH);
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(7, HIGH);
delay(300);
digitalWrite(7, LOW);
digitalWrite(13, LOW);
delay(300);
}
delay(1000);
//Number 9
for(x=0; x<9; x++)
{
digitalWrite(13, HIGH);
digitalWrite(4, HIGH);
digitalWrite(3, LOW);
digitalWrite(2, LOW);
digitalWrite(1, HIGH);
digitalWrite(7, HIGH);
delay(300);
digitalWrite(7, LOW);
digitalWrite(13, LOW);
delay(300);
}
delay(1000);
//Number 5
for(x=0; x<5; x++)
{
digitalWrite(13, HIGH);
digitalWrite(4, LOW);
digitalWrite(3, HIGH);
digitalWrite(2, LOW);
digitalWrite(1, HIGH);
digitalWrite(7, HIGH);
delay(300);
digitalWrite(7, LOW);
digitalWrite(13, LOW);
delay(300);
}
delay(1000);
//Number 6
for(x=0; x<6; x++)
{
digitalWrite(13, HIGH);
digitalWrite(4, LOW);
digitalWrite(3, HIGH);
digitalWrite(2, HIGH);
digitalWrite(1, LOW);
digitalWrite(7, HIGH);
delay(300);
digitalWrite(7, LOW);
digitalWrite(13, LOW);
delay(300);
}
delay(1000);
//Number 0
digitalWrite(13, HIGH);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
delay(2000);
digitalWrite(13, LOW);
//Number 2
for(x=0; x<2; x++)
{
digitalWrite(13, HIGH);
digitalWrite(1, LOW);
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(7, HIGH);
delay(300);
digitalWrite(7, LOW);
digitalWrite(13, LOW);
delay(300);
}
delay(1000);
//Number 0
digitalWrite(13, HIGH);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
delay(300);
digitalWrite(13, LOW);
delay(1000);
//Number 0
digitalWrite(13, HIGH);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
delay(300);
digitalWrite(13, LOW);
delay(1000);
}
Conclusion
The first thing I did was to develop a design solution and then a pseudocode which I later converted to a flowchart and then finally to an actual Arduino code. I immediately identified the pins to be used on the Arduino board and assigned them to Output digital in the setup section of my Arduino code. For my design, I first configured out how to light up the LEDs on the 7 segment display, then I was able to get it working but I ended up using more bits than was necessary. I used up to 8 bits as opposed to 4 bits which I later used. I finally decided to use a BCD decoder which converted a 4 bit binary number to its decimal equivalent. This final design was more efficient and easier to troubleshoot. For the demo, I initially dialed my number without using a loop, but that made my code longer so I created a better algorithm with 4 bits making the program more efficient.
No comments:
Post a Comment