# Problem ## 1 Alter the demo program to add displaying the missing 7-segment digits. ## 2 Test the system with inputs from both the light sensor (PA0) and the first potentiometer (PA1). # Process ## 1 ... ## 2 ... # Answer ## 1 ```c /* ... */ /* Sets the first four pins of Port A pins to analog inputs. */ GPIOA->MODER |= 0xFF; /* Enables the clock for ADC1 by forcing bit 8 of the RCC APB2ENR register to 1. */ RCC->APB2ENR |= 1 << 8; ADC1->CR2 |= 1; /* ... */ /* Enables ADC1 by forcing bit 0 of CR2 to 1. */ ADC1->CR2 |= 1 << 30; /* ... */ /* When ADC1 SQR3 is set to 0, Port A pin 0 (the light sensor) is used for the analog input. When ADC1 SQR3 is set to 1, Port A pin 1 (the first potentiometer) is used for the analog input. */ ADC1->SQR3 = 0; ADC1->SQR3 = 1; /* ... */ volts_hundredths = (300 * analog_value / 4095) % 10; Seven_Segment_Digit(5, volts_hundredths, 0); /* ... */ raw_1000 = (analog_value / 1000) % 10; Seven_Segment_Digit(3, raw_1000, 0); /* ... */ raw_10 = (analog_value / 10) % 10; Seven_Segment_Digit(1, raw_10, 0); raw_1 = (analog_value) % 10; Seven_Segment_Digit(0, raw_1, 0); ``` ## 2 When the light sensor is used for the analog input, the voltage and the raw decimal value changed corresponding to the amount of ambient light around the sensor. * Maximum - `2.8` volts or ... as a raw decimal. * Minimum - `0.1` volts or ... as a raw decimal. When the potentiometer is used for the analog input, the voltage and the raw decimal value changed corresponding to the position of the potentiometer from left to right. * Maximum - `3.0` volts or `4095` as a raw decimal. * Minimum - `0.0` volts or `0` as a raw decimal.