In: Computer Science
Q2. Answer the following questions about the program.
Describe the purpose of the ports and pins being used in the above example. |
|
Describe the effect of changing PinPull_Up to PinPull_None |
|
Describe the effect of changing PinPull_Up to PinPull_Down |
|
Do we need PinDriveStrength_High? Carefully examine the LED board to help in answering this. |
|
Find where Led::setOutput() method is declared and determine the default parameters used if no actual parameters are specified. A little bit tricky! Hint: If you move the cursor to a method and then press F3 an editor window will open at the method declaration. |
|
Find where Switch::setInput() method is declared and determine the default parameters used if no actual parameters are specified. Also a little bit tricky! |
|
Find where GpioC<...> is declared and determine the default template parameters. Which defaults have been used in the example? |
THE CODE IS BELOW:
#include "hardware.h"
using namespace USBDM;
using Switch = GpioC<0, ActiveLow>;
using Led = GpioC<1, ActiveHigh>;
using RedLed = GpioC<3, ActiveLow>;
using BlueLed = GpioA<2, ActiveLow>;
int main() {
Led::setOutput(
PinDriveStrength_High,
PinDriveMode_PushPull,
PinSlewRate_Fast);
RedLed::setOutput(
PinDriveStrength_High,
PinDriveMode_PushPull,
PinSlewRate_Slow);
BlueLed::setOutput(
PinDriveStrength_High,
PinDriveMode_PushPull,
PinSlewRate_Slow);
Switch::setInput(
PinPull_Up,
PinAction_None,
PinFilter_None);
for(;;) {
bool switchValue = Switch::read();
console.write("Switch is ").writeln(switchValue);
Led::write(switchValue);
RedLed::write(!switchValue);
BlueLed::write(switchValue);
}
return 0;
}
1- As the Pins are been set on which they will set the On and Off function as in code we set the pins to do High and Low
2-Pin pull Up will pass the current and it is been the state of ON while the Pin Pull None will be NOTHING as there is only ON button
3- Pin pull Up will pass the current and it is been the state of ON while the Pin Pull Down will be zero as it is the state of OFF
4-Yes it is important as to keep the strength high as we will also be using the resistor.
5- The Led Output() has the default parameters pins drive rate ,strength rate and slew rate.
6- AS it is been called through the library of switch and the default paramerters that are been passed are been listed below
PinAction_None,
PinFilter_None);
7- As it is been Red led out put result and active low are been passed as parameter
PLEASE GIVE A THUMBS UP!!!!!!!!1