Difference between revisions of "Maple Lesson 01 - Blinking LED"
(Created page with "{| style="width: 800px;" |- | == Objective == Using Microduino-CoreSTM32 to control the on-board LED. Actually you can learn to how to use the Micrduino-CoreSTM32's I/O port. ...") |
|||
(2 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
+ | {{Language|第一课--LED灯闪烁实验}} | ||
{| style="width: 800px;" | {| style="width: 800px;" | ||
|- | |- | ||
| | | | ||
− | == Objective == | + | ==Objective== |
− | + | Use the Microduino-CoreSTM32 to control a LED light, and use the Maple IDE to program for the Microduino-CoreSTM32, just like programming in the Arduino IDE. | |
− | == | + | ==Equipment== |
+ | *[[ Microduino-CoreSTM32]] | ||
+ | Microduino-CoreSTM32 is an ARM development board using STM32F103CBT6 chip. It use special Upin7 interface, the size is similar with a coin and fully compatible other Microduino modules. | ||
+ | |||
+ | *Other hardware equipment | ||
+ | **Breadboard Jumper one box | ||
+ | **Breadboard one piece | ||
+ | **LED Light-emitting diodes one | ||
+ | **220ohm resistor one | ||
+ | **USB Data cable one | ||
− | |||
− | == | + | ==Experiment schematic== |
− | |||
− | |||
− | * | + | *There are two connection methods: |
− | ** | + | **LED cathode connects the GND of Microduino-CoreSTM32, and anode connects to Microduino digital I/O port 13, which is the high-level light led. |
+ | **LED cathode connects Microduino-CoreSTM32 digital I/O port 13, anode connects to VCC, so that low-level light led. | ||
+ | [[File: STM32-lesson1Setup.jpg|600px|center|thumb]] | ||
− | + | This experiment will use the first method, you can try another method. | |
− | |||
+ | ==Program== | ||
<source lang="cpp"> | <source lang="cpp"> | ||
− | int led = 13;// Define the | + | int led = 13; //Define the LED control pin |
void setup() { | void setup() { | ||
− | pinMode(led, OUTPUT); // Define the | + | pinMode(led, OUTPUT); //Define the pin as output |
} | } | ||
void loop() { | void loop() { | ||
− | digitalWrite(led, HIGH); // | + | digitalWrite(led, HIGH); //Output higt voltage |
− | delay(1000); | + | delay(1000); // Delay 1s |
− | digitalWrite(led, LOW); // | + | digitalWrite(led, LOW); //Output low voltage |
− | delay(1000); | + | delay(1000); // Delay 1s |
} | } | ||
</source> | </source> | ||
− | * | + | Let's analyze the program: |
+ | *Firstly define a control pin, we used the pin 13, you can can change it to (0 ~ 21) accroding to your requirement. | ||
+ | '''Note: 0 ~ 13 mapping to D0 ~ D13 and 14 ~ 21 mapping to A0 ~ A7 on board. For example, if you want to use A0 to control the LED, need change the “int led = 13;” to “int led = 14;”''' | ||
+ | *setup() function is the initralization function, and only is executed one time. | ||
+ | *loop() function is a loop function which will run the inside program in loop. In this example, output the high voltage in pin, then output low voltage after 1s, then dalay 1s again befort stop. Then repeat this procedure, so you can see the LED blinks. | ||
+ | *pinMode(pin,mode) function defines the state of PIN as outpur or input. | ||
+ | *digitalWrite(pin,HIGH) function controls the output, high or low. | ||
+ | *delay(ms) function use to delay, the unit is ms. | ||
+ | |||
<source lang="cpp"> | <source lang="cpp"> | ||
− | int | + | int led=13; |
− | + | void setup() { | |
− | + | // Set up the built-in LED pin as an output: | |
− | void setup() | + | pinMode(led, OUTPUT); |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
+ | |||
+ | void loop() { | ||
+ | togglePin(led); // Turn the LED from off to on, or on to off | ||
+ | delay(1000); // Wait for 1 second (1000 milliseconds) | ||
} | } | ||
</source> | </source> | ||
− | + | Grammatical information: | |
− | + | togglePin(led):Swith the specific pin's output value. If the pin is high voltage, then set it to low voltage, otherwise set it to high. | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | ==Debug== | ||
+ | *Connect the module accordign the shcematic. | ||
+ | [[File: STM32-lesson1yuanli.jpg|600px|center|thumb]] | ||
+ | *Open the Maple IDE, copy the program to editor, then choose the board type (Microduino-CoreSTM32 to Flash). Click the download button or shortcut key (Ctrl+U) to download program. | ||
+ | *After download, you can see the LED blinking every 1s. You also can change to other parameter to try. | ||
|} | |} |
Latest revision as of 06:16, 17 August 2014
Language: | English • 中文 |
---|
ObjectiveUse the Microduino-CoreSTM32 to control a LED light, and use the Maple IDE to program for the Microduino-CoreSTM32, just like programming in the Arduino IDE. EquipmentMicroduino-CoreSTM32 is an ARM development board using STM32F103CBT6 chip. It use special Upin7 interface, the size is similar with a coin and fully compatible other Microduino modules.
Experiment schematic
This experiment will use the first method, you can try another method. Programint led = 13; //Define the LED control pin
void setup() {
pinMode(led, OUTPUT); //Define the pin as output
}
void loop() {
digitalWrite(led, HIGH); //Output higt voltage
delay(1000); // Delay 1s
digitalWrite(led, LOW); //Output low voltage
delay(1000); // Delay 1s
} Let's analyze the program:
Note: 0 ~ 13 mapping to D0 ~ D13 and 14 ~ 21 mapping to A0 ~ A7 on board. For example, if you want to use A0 to control the LED, need change the “int led = 13;” to “int led = 14;”
int led=13;
void setup() {
// Set up the built-in LED pin as an output:
pinMode(led, OUTPUT);
}
void loop() {
togglePin(led); // Turn the LED from off to on, or on to off
delay(1000); // Wait for 1 second (1000 milliseconds)
} Grammatical information: togglePin(led):Swith the specific pin's output value. If the pin is high voltage, then set it to low voltage, otherwise set it to high. Debug
|