I have gotten stuck no an arduino lab, and was wondering if I could get some hel
ID: 2293848 • Letter: I
Question
I have gotten stuck no an arduino lab, and was wondering if I could get some help.
Using FreeRTOS to create a system that you can interrupt with the Button on Pin 2. When you interrupt then flash the LED on Pin 3. The length of the flash should be determined by the number of times the button is pressed, increasing by 100 msec up to 2 seconds. Use a queue to pass this length of time between the ISR and the LED process. Use the second LED to indicate that the system is ready for another button press.
Explanation / Answer
Step-by-Step Instructions
Insert the short leg of the LED into the GND pin on your Arduino (use the GND pin closest to pin 13).
Connect the 220 Ohm resistor to pin 13 on the Arduino. It doesn’t matter which way you connect the resistor.
Use the alligator clip to connect the long leg of the LED to the other leg of the resistor. If you do not have an alligator clip, twist the two leads together as best you can to get a steady electrical connection.
Plug the Arduino board into your computer with a USB cable.
Open up the Arduino IDE.
Open the sketch for this section.
Click the Verify button on the top left. It should turn orange and then back to blue.
Click the Upload button. It will also turn orange and then blue once the sketch has finished uploading to your Arduino board.
Now monitor the Arduino board – the LED should be blinking.
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
Most Arduinos have an on-board LED you can control. On the Uno and
Leonardo, it is attached to digital pin 13. If you're unsure what
pin the on-board LED is connected to on your Arduino model, check
the documentation
This example code is in the public domain.
modified 8 May 2014
by Scott Fitzgerald
*/
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
The next block of code you encounter in the Blink sketch is…
void setup( ) {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
1
2
3
4
void setup( ) {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
Recall that the setup() function is in almost every Arduino sketch you encounter. Inside the curly braces is code that will only be run once by the Arduino. For this sketch notice the function pinMode() is inside the curly braces of the setup() function.
Let me start by saying that pinMode() is a wonderful function. If you recall, functions can take arguments. The pinMode() function takes two arguments – it wants a pin number and a mode for that pin. The pin number is easy, 0 to 13 for digital pins, and A0 to A5 for analog pins.
The mode is an easy designation as well, you want the pin to be either an INPUT (good for reading a sensor) or an OUTPUT (good for powering an LED).
When a pin is set as an INPUT, it prepares the pin to read voltages that will be applied at the pin. When a pin is set as an OUTPUT, it prepares the pin to output voltage – more on this later.
Moving on to the final block of code, we come to our favorite and ubiquitous function void loop()…
void loop( ) {
digitalWrite(led,HIGH);// turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led,LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
1
2
3
4
5
6
void loop( ) {
digitalWrite(led,HIGH);// turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led,LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
You may recall that void loop() runs over and over again. In this loop, we see two functions: digitalWrite() and delay().
The function digitalWrite() is used to apply either HIGH or LOW voltage to a pin. HIGH will apply 5 volts to the pin you designate and LOW will apply 0 volts. If you apply 5 volts to a pin that is connected through an LED to ground, then the LED will light up.
There is a voltage difference between the pin and ground, thus current is able to flow through the LED. If you apply 0 volts to the same pin the LED will not light up because no current is being “pushed” through the circuit – the voltage at ground and at the pin are both zero.
digitalWrite() takes two arguments, the pin number and the level of voltage, either HIGH or LOW, as we have discussed above.
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
1
2
digitalWrite() takes two arguments, the pin number and the level of voltage, either HIGH or LOW, as we have discussed above.
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
We want to start the loop by applying HIGH voltage to pin 13, where our LED is attached. In the digitalWrite() function we use the variable name ‘led’ to refer back to the value 13 – which was previously assigned.
Notice that there is no need to explicitly write 13 in the digitalWrite() function, instead we are able to use the variable ‘led’. Variables are awesome like that – they can take the place of numbers and are much easier to change and track. Every time we use the ‘led’ variable, the Arduino will see 13. If we later decide to move our LED to pin 10, then all we have to do is change the value of ‘led’ once, and all the instances of ‘led’ are changed too.
Once digitalWrite() function has been executed, the LED will get bright – we just applied 5 volts, so hey, that makes sense. The next thing we do is delay the Arduino sketch to enjoy the bright glow of our LED. To do this, we use the delay() function.
The delay() function takes one argument – the number of milliseconds you want the program to delay. In this case, we want 1000 milliseconds, which equals one second.
First we said, “apply high voltage” and now we say – wait one second. Our LED will glow for exactly one second. But that gets old, and we have to stay true to the name of the sketch, so next we tell the Arduino to write a LOW voltage to pin 13 – to do this we use the same function as before, namely digitalWrite(), but, this time, we want LOW voltage instead of HIGH.
Now the LED goes dark because no current is flowing. In order to sustain that darkness we use the delay() function again for one second. Now the LED is dark for one second.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.