Question

In: Computer Science

Q1) Modify the following code to sequentially display 154628577990449700 /* DisplayDigitsUsingIndexedArray - Sequentially displays digits 0...

Q1) Modify the following code to sequentially display 154628577990449700

/* DisplayDigitsUsingIndexedArray - Sequentially displays

digits 0 - 9 using an indexed array and register I/O

Written by Duncan McGehee

1 October 2011 */

/*PORTD.7 is connected to the A-segment of the 7-segment display

PORTD.6 = B, PORTD.5 = C, PORTD.4 = D, PORTD.3 = E

PORTD.2 = F, PORTD.1 = G */

/* Declare an array of binary numbers that will be used to drive

the 7-segment display. This is done once, globally, so that we

don't redeclare it each time the program loops */

byte DisplayNumbers[] = {B11111100, B01100000, B11011010, B11110010,

                        B01100110, B10110110, B10111110, B11100000,

                        B11111110, B11110110};

void setup()

{

DDRD = B11111110; /* DDRD is the direction register for

the Arduino's PORT D (Digital Pins 0 - 7). DDRD = B11111110

tells Arduino to set pin 0 for input, pins 1 through 7 for output */

}

void loop() //This function loops forever

{

    //Send each digit to the 7-segment display for .5 second

for (byte index = 0; index <= 9; index++)

{

    PORTD = DisplayNumbers[index]; //Use the indexed array to choose the digit

    delay(500);

}

//turn off the 7-segment display for half a second

PORTD = B00000000;

delay(500);

}

Solutions

Expert Solution

Please up vote ,comment if any query . Thanks for question . Be safe .

Note : check attached image for simulation output ,code compiled in ARDUINO IDE and simulation tested in Proteus VSM .

Program Plan :

  1. Create array of size 18 with sequential output .
  2. display one by one each digit on segment with delay of 500milli second .

Program :

/* DisplayDigitsUsingIndexedArray - Sequentially displays

digits 0 - 9 using an indexed array and register I/O

Written by Duncan McGehee

1 October 2011 */

/*PORTD.7 is connected to the A-segment of the 7-segment display

PORTD.6 = B, PORTD.5 = C, PORTD.4 = D, PORTD.3 = E

PORTD.2 = F, PORTD.1 = G */

/* Declare an array of binary numbers that will be used to drive

the 7-segment display. This is done once, globally, so that we

don't redeclare it each time the program loops */
/*
byte DisplayNumbers[] = {B11111100, B01100000, B11011010, B11110010,

                        B01100110, B10110110, B10111110, B11100000,

                        B11111110, B11110110};*/
//Create new array of DisplayNumbers with value of size 18
//1,5,4,6,2,8,5,7,7,9,9,0,4,4,9,7,0,0
byte DisplayNumbers[]={B01100000,B10110110,B01100110,B10111110,B11011010,B11111110,B10110110,B11100000,B11100000, B11110110, B11110110,B11111100,
                       B01100110,B01100110,B11110110, B11100000,B11111100,B11111100
                      };
void setup()

{

DDRD = B11111110; /* DDRD is the direction register for

the Arduino's PORT D (Digital Pins 0 - 7). DDRD = B11111110

tells Arduino to set pin 0 for input, pins 1 through 7 for output */

}

void loop() //This function loops forever

{

    //Send each digit to the 7-segment display for .5 second
//display element from array index 0 to 17
for (byte index = 0; index < 18; index++)

{

    PORTD = DisplayNumbers[index]; //Use the indexed array to choose the digit

    delay(500);

}

//turn off the 7-segment display for half a second

PORTD = B00000000;

delay(500);

}

Simulation Output :

Please comment if you want any changes .


Related Solutions

Design a four bit down counter with a 7 segment display (hexadecimal digits 0-F) Part 1:...
Design a four bit down counter with a 7 segment display (hexadecimal digits 0-F) Part 1: Implement a seven segment display for hexadecimal digits (0-F). Recommended to first try implementing the seven segment displays for each of the hexadecimal digits using switches as inputs. Part 2: Implement a four bit down counter. When this component is complete, add the counter and wire the outputs of the JK flip flops to where the switches were once. The last JK flip flop...
Given the following code for AES Electronic Code Block implementation for the encryption functionality. Modify the...
Given the following code for AES Electronic Code Block implementation for the encryption functionality. Modify the code to create a function named ‘encryptECB(key, secret_message)’ that accepts key and secret_message and returns a ciphertext.          #Electronic Code Block AES algorithm, Encryption Implementation from base64 import b64encode from Crypto.Cipher import AES from Crypto.Util.Padding import pad from Crypto.Random import get_random_bytes secret_message = b" Please send me the fake passport..." password = input ("Enter password to encrypt your message: ") key= pad(password.encode(), 16) cipher...
Write VHDL code for the following: Use HEX-to-seven segment display converters to display the inputs and...
Write VHDL code for the following: Use HEX-to-seven segment display converters to display the inputs and results for a 4-bit adder. The inputs are unsigned 4-bit binary numbers. The outcome is a 4-bit binary adder with LED display. First you need to create a symbol for the HEX-to-seven segment display converter. Then implement a 4-bit adder using VHDL. Finally, connect three HEX-to-seven segment display converters to display input X, input Y, and sum S.
Write an assembly program that displays the following two options: 1. Display the current date. 2....
Write an assembly program that displays the following two options: 1. Display the current date. 2. Enter a date for a meeting and display remaining days. If the user selects the first option, the program should display the current date in dd/mm/yyyy format. If the user selects the second option, the program asks the user to enter a date for a meeting within year 2020 (in decimal) in dd/mm format. The program then calculates and displays the number of days...
Modify the RetirementGoalapplication to display the amount of money the user will have if the user...
Modify the RetirementGoalapplication to display the amount of money the user will have if the user earns 4%interest on the balance every year. In java pls given code. import java.util.Scanner; public class RetirementGoal2 { public static void main (String[] args) { Scanner input = new Scanner(System.in); int years; int saveAmount; int total; final double RATE; // perform interest calculation System.out.print("How many years until retirement? >> "); years = input.nextInt(); while(years <= 0) { System.out.println("Years cannot be 0 or negative"); System.out.print("Please...
4. Given the following code for AES Electronic Code Block implementation for the encryption functionality. Modify...
4. Given the following code for AES Electronic Code Block implementation for the encryption functionality. Modify the code to create a function named ‘decryptECB(key, ciphertext)’ that accepts key and ciphertext and returns a plaintext. from base64 import b64decode from Crypto.Cipher import AES from Crypto.Util.Padding import pad from Crypto.Util.Padding import unpad # We assume that the password was securely shared beforehand password = input ("Enter the password to decrypt the message: ") key= pad(password.encode(), 16) ciphertext = input ("Paste the cipher...
Java code for a binary tree that does the following:  Display a menu to the...
Java code for a binary tree that does the following:  Display a menu to the user and request for the desired option.  Based on the user’s input, request for additional information as follows: o If the user wants to add a node, request for the name (or ID) of the new node to be added as well as the name of the desired parent of that node.  If the parent node already has two children, the new...
Java code for a binary tree that does the following:  Display a menu to the...
Java code for a binary tree that does the following:  Display a menu to the user and request for the desired option.  Based on the user’s input, request for additional information as follows: o If the user wants to add a node, request for the name (or ID) of the new node to be added as well as the name of the desired parent of that node.  If the parent node already has two children, the new...
Take the following code and modify the if(args >= 3) statement to work with a dynamic...
Take the following code and modify the if(args >= 3) statement to work with a dynamic amount of inputs. Example: ./cat file1 file2 file3 file4 filen-1 filen should output a text file that concatenates the files file1 to filen into one file #include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) {    char ch;    if (argc ==1)    {        while((ch = fgetc(stdin)) != EOF) fputc(ch, stdout);    }    if (argc == 2)    {   ...
Using python Write a program that displays all of states in the U.S. and display each...
Using python Write a program that displays all of states in the U.S. and display each state that begins with the letter A.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT