Ask Question

Write a program in C that reads a 3-bit desired light pattern from the 3 input switches connected to pins P2.3-P2.5 and displays the pattern on the 8 LEDs (pins P1.0-P1.7) with some ""light playing"" options based on the input from other 3 switches (pins P2.0-P2.2).

+2
Answers (1)
  1. 7 July, 06:08
    0
    Check the explanation

    Explanation:

    #include

    main ()

    { int k=1, p, l, i;

    int p2[8], p1[8];

    for (i=0; i<8; i++) {

    p1[i]=0;

    p2[i]=0;

    }

    while (k==1)

    {

    printf ("enter the pin inputs from p2.3-p2.5:");

    scanf ("%d%d%d",&p2[3],&p2[4],&p2[5]);

    printf ("Press Logic 0 for on and 1 for off on switch port p2.0/n");

    scanf ("%d",&l);

    p1[3]=p2[3];

    p1[4]=p2[4];

    p1[5]=p2[5];

    if (l==0)

    {p=1;

    for (i=0; i<8; i++)

    printf ("p1.%d : %d/n", i, p2[i]);

    printf ("/n press either 1 to continue or 0 to stop : ");

    scanf ("%d",&p);

    printf ("/n");

    while (p==1)

    { printf ("enter the pin inputs from p2.3-p2.5:");

    scanf ("%d%d%d",&p2[3],&p2[4],&p2[5]);

    p1[3]=p2[3];

    p1[4]=p2[4];

    p1[5]=p2[5];

    for (i=0; i<8; i++)

    printf ("p1.%d : %d/n", i, p2[i]);

    printf ("/n press either 1 to continue or 0 to stop : ");

    scanf ("%d",&p);

    printf ("/n");

    }

    }

    else

    {

    printf ("After Rotation of pattern : /n");

    for (i=0; i<8; i++)

    { if (p2[i]==0)

    printf ("p1.%d : 1/n", i);

    else

    printf ("p1.%d : 0/n", i);

    }

    }

    printf ("press 0 for on and 1 for off on switch port p2.1 : /n");

    scanf ("%d",&l);

    if (l==0)

    { printf ("/nLeft Rotation of pattern from read mode : /n");

    printf ("p1.0 : %d/n", p1[0]);

    printf ("p1.1 : %d/n", p1[5]);

    printf ("p1.2 : %d/n", p1[6]);

    printf ("p1.3 : %d/n", p1[3]);

    printf ("p1.4 : %d/n", p1[2]);

    printf ("p1.5 : %d/n", p1[1]);

    printf ("p1.7 : %d/n", p1[6]);

    printf ("p1.7 : %d/n", p1[7]);

    }

    else

    {printf ("/nRight rotation of pattern from read mode: / n");

    printf ("p1.0 : %d/n", p1[0]);

    printf ("p1.1 : %d/n", p1[1]);

    printf ("p1.2 : %d/n", p1[2]);

    printf ("p1.3 : %d/n", p1[7]);

    printf ("p1.4 : %d/n", p1[6]);

    printf ("p1.5 : %d/n", p1[5]);

    printf ("p1.7 : %d/n", p1[4]);

    printf ("p1.7 : %d/n", p1[3]);

    }

    printf ("press 0 for on and 1 for off on switch port p2.2 : /n");

    scanf ("%d",&l);

    if (l==0)

    printf ("Make Rotation fast/n");

    else

    printf ("Make Rotation slow/n");

    printf ("Enter 1 to continue or 0 to exit:");

    scanf ("%d",&k);

    printf ("/n");

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a program in C that reads a 3-bit desired light pattern from the 3 input switches connected to pins P2.3-P2.5 and displays the ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers