complex C programs it becomes very important to ensure tha a closing brace, at t
ID: 3887306 • Letter: C
Question
complex C programs it becomes very important to ensure tha a closing brace, at the right place. ts 0, 1. /*Prográm Example 3.5: Simple demonstration of 7-segment display. Display digi 2. 3 in turn. include "mbed . h" BusOut display (p5.p6.p7,p8.p9.p1o.pl1.p12): // segments a.b.c.d.e,f.g.dp int main) f while(1) I for(int i-0: i4: i+t) switch (i)f //display. 0 /display 0 //display 1 case 0: display0x3F: break; case 1: display0x06: break; case 2: display 0x5B; break; case 3: display=0x4F; break; //end of switch wait(0.2); //end of for //end of while /end of main Tuomnle 35 Isine for to sequence values to a seven-segment displayExplanation / Answer
for program-3,to turn led on when the respective value of i is taken as given..
#include "mbed.h" //include the mbed header file as part of this program
// program variable leda,ledb,ledc,ledd is created, and linked with mbed LED1,LED2,LED3,LED4 repectively
DigitalOut leda(LED1);
DigitalOut ledb(LED2);
DigitalOut ledc(LED3);
DigitalOut ledd(LED4);
int main()
{ //the main function starts here
while(1)
{ //a continuous loop is created
for(int i=0; i<4; i++)
{
switch (i)
{
case 0: leda=1;ledb=0;ledc=0;ledd=0; break; //on the first led and off all other
case 1: leda=0;ledb=1;ledc=0;ledd=0; break; //on the second led and off all other
case 2: leda=0;ledb=0;ledc=1;ledd=0; break;
case 3: leda=0;ledb=0;ledc=0;ledd=1; break;
}
wait(0.2); //wait 0.2 seconds
} //end of while loop
} //end of main function
program-4----using if-else for third program----------------------------------
#include "mbed.h" //include the mbed header file as part of this program
// program variable leda,ledb,ledc,ledd is created, and linked with mbed LED1,LED2,LED3,LED4 repectively
DigitalOut leda(LED1);
DigitalOut ledb(LED2);
DigitalOut ledc(LED3);
DigitalOut ledd(LED4);
int main()
{ //the main function starts here
while(1)
{ //a continuous loop is created
for(int i=0; i<4; i++)
{
if(i==0) {
leda=1;ledb=0;ledc=0;ledd=0; //on the first led and off all other
}
else if(i==1) {
leda=0;ledb=1;ledc=0;ledd=0; //on the second led and off all other
}
else if (i==2) {
leda=0;ledb=0;ledc=1;ledd=0;
}
else {
leda=0;ledb=0;ledc=0;ledd=1;
}
wait(0.2); //wait 0.2 seconds
} //end of for loop
} //end of while loop
} //end of main function
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.