3. (40 points) This program should rotate the LEDs using both variable delay and
ID: 2292535 • Letter: 3
Question
3. (40 points) This program should rotate the LEDs using both variable delay and direction. The delay and direction should be controlled by the on-board potentiometer, which is read by the analog to digital converter (ADC) on the microcontroller. When the arrow on the potentiometer is pointing straight up (toward the edge of the board where the PICkit3 programmer connects), the LEDs should not change at all. (Note that it may be difficult to determine this exact position.) If the arrow points to the left of that position, the LEDs should rotate left; if the arrow points to the right of that position, the LEDs should rotate right. The speed of rotation is dependent on how far from the center the arrow is, as shown below Please note that "fast rotation" should still be slow enough that you can see the LEDs rotating-they shouldn't change so fast that all lights appear to be on Fast rotation to left Slow rotation to left Slow rotation to right Fast rotation to right No rotation In addition to using the potentiometer to control direction and speed of rotation, this exercise should use the switch to enable and disable rotation. If the switch is pressed while the LEDs are rotating, the system should pause in its current position, regardless of whether the ADC input value changes. If the switch is pressed while everything is paused, the system should resume rotating in the appropriate direction based on the ADC input value. Demonstration (15 points): You must show that the potentiometer controls the direction and speed of rotation in the manner described -both slow and fast rotation in either direction, as well as pausing when the potentiometer is centered. You must also show that the button toggles the mode of operation-press the button to pause the system, and move the potentiometer to showExplanation / Answer
CODE:
#define PORT_OFF(port,pin) port &= ~(1<<pin)
int main(void)
{
unsigned int input;
DDRD=0xff;
PORTD = 0x00;
ADCSRA = (1<<ADEN) | (1<<ADPS2) | (1<<ADPS0);
ADMUX=0x05;
while (1)
{
ADCSRA |= (1<<ADSC);
while (ADCSRA & (1<<ADSC));
input = ADCW;
if (input < 512)
{
PORT_OFF(PORTD,7);
PORT_ON (PORTD,6);
}
else
{
PORT_ON(PORTD,7);
PORT_OFF (PORTD,6);
}
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.