Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 2. Consider an 8-light lighting system that is controlled by an array of

ID: 3743031 • Letter: P

Question

Problem 2. Consider an 8-light lighting system that is controlled by an array of 8-bit registers. The first element of the array controls light #1, the second element of the array controls light #2, and so on. We call these registers Light Status Register or LSR. For each LSR, the bits control the light based on the below specification . Bit 7-6: control the light intensity: 00 off, 01 low, 10 medium, 11 high. . Bit 5-4: control the color: blue 00, green 01, red 10, yellow 11 . Bit 3 controls whether the light flickers: 0 no flicker, 1 flicker. o Bit 2-0 are unused. Examples: If we write 0x0 to an LSR, it means that the corresponding light should be off. If we write 0xFF to an LSR, it means that the corresponding light should be yellow with the highest intensity and it should flicker. · . . If we write 0x68 to an LSR, it means that the corresponding light should be low intensity red with flicker.

Explanation / Answer

CODE:

#include<stdio.h>

int cureentIntensity[8];

int currentColor[8];

void storeCommand(unsigned int cmd)

{

int lampNo = cmd & 7 ; // 00000 111 // masking last three bit

int color = (cmd & (00111000)) >> 3; // data left shifting by 3. to get actual digit

int intensity = (cmd & (11000000))>>6; // masking first two bit and make it shift right by 6

printf("Lamp number is %d ",lampNo);

switch(color) // getting and storing color information

{

case 0: // 000 blue

printf("color blue ");

currentColor[lampNo] = 0;

break;

case 1: // 001 Green

printf("colour Green ");

currentColor[lampNo] = 1;

break;

case 3: // 011 yellow

printf("colour yellow ");

currentColor[lampNo] = 3;

break;

case 4: // 100 white

printf("colour white ");

currentColor[lampNo] = 4;

break;

default:

printf("Invalid colour ");

}

switch(intensity) // getting and storing intensity information

{

case 0: // 00 off

printf("off ");

cureentIntensity[lampNo] = 0;

break;

case 1: // 01 low

printf("low ");

cureentIntensity[lampNo] = 1;

break;

case 2: // 10 medium

printf("medium ");

cureentIntensity[lampNo] = 2;

break;

case 3: // 11 High

printf("High ");

cureentIntensity[lampNo] = 3;

break;

default:

printf("Invalid");

}

}

int main()

{

storeCommand(0xc3);

}

OUTPUT:

Lamp number is 3

color blue

High

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote