Part D: Lab assignment If you fully understand the code in Part C, you can now m
ID: 3726051 • Letter: P
Question
Part D: Lab assignment If you fully understand the code in Part C, you can now move on to solving the lab assignment. Develop a system using the eight LEDs and the pushbutton that has four LED modes: Mode 1: The LEDs blink one after another from left to right, then repeat from the left. Mode 2: The LEDs blink one after another from right to left, then repeat from the right Mode 3: The LEDs blink back and forth. Mode 4: The LEDs blink on and off all together. Whenever the pushbutton is pressed, the system should change modes, starting with mode 1, then 2, then 3, then 4, and then back to 1 Hints Use a variable to keep track of which mode you are in; for example, an integer variable that increases by 1 whenever the button is pressed and resets to O when it hits 4 would work well. .Use a variable to control which LED is blinking, as in Part B. Every time through the loop, modify this variable based on the mode. Don't forget to delay! Otherwise your LEDs will flash at 12MHz which is far too fast for your eye to seeExplanation / Answer
I make solution by using c++
#include<iostream>
#include<stdlib.h>
using namespace std;
void mode1()
{
char a[7];
for(int k=0;k<2;k++)
for(int j=0;j<7;j++)
{
for(int i=0;i<7;i++)
{
a[i] = '@';
if(i==j)
a[i] = ' ';
cout<<a[i] << " ";
}
system ("CLS");
}
}
void mode2()
{
char a[7];
for(int k=0;k<2;k++)
for(int j=6;j>=0;j--)
{
for(int i=0;i<7;i++)
{
a[i] = '@';
if(i==j)
a[i] = ' ';
cout<<a[i] << " ";
}
system ("CLS");
}
}
void mode3()
{
char a[7];
for(int k=0;k<2;k++)
{
for(int j=0;j<7;j++)
{
for(int i=0;i<7;i++)
{
a[i] = '@';
if(i==j)
a[i] = ' ';
cout<<a[i] << " ";
}
system ("CLS");
}
for(int j=6;j>=0;j--)
{
for(int i=0;i<7;i++)
{
a[i] = '@';
if(i==j)
a[i] = ' ';
cout<<a[i] << " ";
}
system ("CLS");
}
}
}
void mode4()
{
char a[7];
for(int k=0;k<2;k++)
{
for(int i=0;i<7;i++)
cout<<"@"<<" ";
system ("CLS");
for(int i=0;i<7;i++)
cout<<" "<<" ";
system ("CLS");
}
}
int main()
{
int n;
cout<<"press push button by click 1";
while(1)
{
cin>>n;
if(n==1)
{
mode1();
}
cin>>n;
if(n==1)
{
mode2();
}
cin>>n;
if(n==1)
{
mode3();
}
cin>>n;
if(n==1)
{
mode4();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.