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

Write a program in C (Not Python) to be run on a Raspberry Pi that wil interface

ID: 3854864 • Letter: W

Question

Write a program in C (Not Python) to be run on a Raspberry Pi that wil interface to 3 LEDs and 2 switches. The LEDs are on GPIO 23, 24, and 25. The switches are on GPIO 17, and 18. The program will make the LEDs to blink in a "Knight Rider" pattern, meaning that when LED A turns off, LED B turns on, then when LED B turns off, LED C turns on. Once LED C turns off, then LED B needs to turn back on. So the LED will blink back and forth.

The program must meet this criteria:

o When switch A is pressed, all LEDs will light. Each LED must exhibit normal brightness: not too bright and not too dim. This means you should use your knowledge from Lab 1 when deciding how to interface your hardware.

o When switch B is pressed and switch A is not pressed, the LEDs will cycle in a knight rider pattern where only one LED is lit at a time and the LED appears to bounce from side to side. The speed of bounce must be slow enough to see.

o When both switches are pressed, all LEDs will light. Same as first item. Basically switch A has priority.

o When no switch is pressed, all LEDs will be off.

Explanation / Answer

#include<stdio.h>

main()

{ printf("1 stand for on and 0 stand for off ");

printf("press input of switch A and B:");

int x,y;

scanf("%d%d",&x,&y);

if(x==0&&y==0 )

printf("LEDs are turned off : 0 0 0 ");

if(x==0 && y==1)

{ int i=0,j=0;

//printf("Enter How much time this pattern should lit: ");

int n;

printf("LEDs pattern: ");

while(j<100)

{ for(i=1;i<=3;i++)

{if(i==1)

printf("1 0 0 ");

else if(i==2)

printf("0 1 0 ");

else

printf("0 0 1 ");

}

for(i=2;i>=1;i--)

{if(i==2)

printf("0 1 0 ");

else

printf("1 0 0 ");

  

}

j++;

}

}

if(x==1 && y==0)

printf("LEDs are turned on : 1 1 1 ");

if(x==1&&y==1)

printf("LEDs are turned on : 1 1 1 ");

}

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