Lesson 1--LED flashes experiment

来自Microduino Wikipedia
跳转至: 导航搜索
Language English

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 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.

This experiment will use the first method, you can try another method.

Program

int 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:

  • Firstly define a control pin, we used the pin 13, you can change it to (0 ~ 21) according 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 initialization 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 delay 1s again before stop. Then repeat this procedure, so you can see the LED blinks.
  • pinMode(pin,mode) function defines the state of PIN as output or input.
  • digitalWrite(pin,HIGH) function controls the output, high or low.
  • delay (ms) function use to delay, the unit is ms.
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):Switch 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 according the schematic.
  • 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.