To get started, let's look at the LED that's built into the Arduino itself and connected to pin 13. Start with the program block we had before. Now get the LED Module block which you can find in the DFRobot category. Drag it out so the dimple on the top left corner of the LED Module block aligns with the bump on the top right of the loop block. Notice that the loop expands to hold it. There are two small blocks stuck on the right side of the LED Module block: pin# and status. We want to control the LED connected to pin# 13 but it defaults to pin# 1. By clicking the 1, you can change it. We want it to turn the LED on, so don't change the status block. Next get the delay MILLIS block from the bottom of the Control category (making sure not to get the delay MIRCOS) and drag that to the bottom of the LED Module block. It defaults to a delay of 1000 milliseconds (1 second) but let's make it blink faster. Change the 1000 to 500 so the LED will stay on for only a half second. Then we need to turn it off so get another LED Module block and change it to pin# 13 also. This time we want the LED to turn off, so change the status to OFF. Finally add another delay of 500 milliseconds and you program should look like this:
Make sure that you robot is plugged into the USB cable and click the Upload button at the top of the ArduBlock window. This translates your code into Processing language in the Arduino IDE and send it to your robot. Did the LED on your robot start blinking?
At this point, we can look at the code that was created or if you don't use ArduBlock, you can type this to get the same result:
void setup()
{
pinMode( 13 , OUTPUT);
}
void loop()
{
digitalWrite( 13 , HIGH );
delay( 500 );
digitalWrite( 13 , LOW );
delay( 500 );
}
Remember, we still need the setup and loop sections. In the setup section, we tell the robot that we will be using pin 13 as an output pin rather than an input pin. Then, in the loop section we set pin 13 to high with the digitalWrite command. This mean there is high voltage (5V) going to that pin. Then we delay for 500 milliseconds before setting pin 13 to low or 0V. If you make any changes to the code, they won't be translated back to ArduBlock, but you can still upload them to the robot by clicking File >> Upload in the Arduino IDE.
Independent Challenge: Long Blink
Now that you have the LED blinking for a half second on and a half second off, go back and change the code in either Arduino IDE or ArduBlock to make the LED blink on for two seconds and off for a quarter second.