Not very impressive? Rome wasn’t built in a day and a program of a thousand megabytes begins with a single line. Blink program is Hello World equivalent for people learning programming on embedded systems. It is the first step towards understanding how computers sense and interact with real world, the logic and syntax needed to write more complex programs, that will allow us to implement our ideas in life. So, let me get started from here!
In Grove beginner kit there's one LED module included - LEDs contain semiconductor materials that are used as a light source. When a voltage is applied, the movement of electrons produces light.
I need to make the LED shine with a couple of blocks of code. I chose to use TinkerGen IDE called Codecraft, it's an easy-to-use graphical programming tool.
Step 1: Overview of the programming interface
After opening Codecraft, select Arduino Uno/Mega/Beginner Kit as my device and you'll see the following interface.
Step 2: Add setup and loop blocks
In the start column of the block classification area, you can see the setup and loop blocks. The blocks within setup part are executed in sequence once, on the board startup (or after you press reset button). The blocks within loop part are executed in sequence and after the final block has finished executing, the board goes back to the first block and repeats the whole process - this is why it is called loop. Let me put this setup-loop block and upload my first program. Click on Start category then click on setup-loop block and drag it to the Scripts area. Once it's there, click on upload button choose the port to which the board is connected and press Upload.
Step 3: Procedure for lighting the LED
Okay, now what? My board doesn't seem to be doing ANYTHING. This is precisely because it's been instructed to do nothing. Let me add a block LED pin... state... to the setup part. Set the Pin number to D4 - this is where the LED module is connected to the mainboard.
Step 4: Connect the Grove Beginner Kit
Connect the Grove Beginner Kit to the computer with a USB data cable, as shown in the figure below, and click the "Upload" button.
Upload until seeing a successful prompt.
Let there be light! A 5V electric current, consisting of electrons, flows from the main board to LED and makes semiconductor material inside of it to glow.
Step 5: Light ON/OFF
Now if you wanted to switch off the LED, you could just change LED Pin D4 state On to LED Pin D4 state Off and re-upload the program. But doing it every time manually would be tiresome. Could we just place two blocks LED Pin D4 state On and LED Pin D4 state Off in a sequence? Of course.
Hm, that didn’t work. Is your LED broken?
Not really. The microchip inside of the board did exactly what you instructed it to do -it closed the circuit allowing the electrons to flow and then opened it stopping the flow of electrons. It is just it happened way too fast for your eyes to see the difference.
Let’s add delay block, which you can find in Control category, to slow things down a bit. And here we have it! Our first blinking LED!
Comments
Please log in or sign up to comment.