你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

ARM®mbed OS入门开发(三 F)Nucleo 控制继电器

[复制链接]
anywill 提问时间:2016-10-20 16:05 /
ARM®mbed OS入门开发(三 F)Nucleo 控制继电器

#include"mbed.h";
//按下蓝色按键后四个继电器动作
Serial pc(SERIAL_TX, SERIAL_RX);    // This is USART2 tx, rx - It is used for debug (Usb Virtual Com)
Serial device(PB_6, PA_10);         // This is USART1 tx, rx
//------------------------------------
// UART configuration:
// 9600 bauds, 8-bit data, no parity
//------------------------------------


DigitalIn mybutton(USER_BUTTON);
DigitalOut LED(PA_5);      
DigitalOut RL1(PA_8);       // 继电器n.1
DigitalOut RL2(PB_10);      // 继电器 n.2
DigitalOut RL3(PB_4);       //继电器 n.3
DigitalOut RL4(PB_5);       //继电器n.4

#define NonPremuto 1
#define Premuto    0

void OnRELE_forTime(int Rele, float Tempo);

int main()
{
  while(1)
  {
    if (mybutton == Premuto)
    {  
        // Button is pressed
        LED = !LED;             // Toggle the LED state
        OnRELE_forTime(1, 2);   // ON RL1 for 2sec
        OnRELE_forTime(2, 2);   // ON RL2 for 2sec
        OnRELE_forTime(3, 2);   // ON RL3 for 2sec
        OnRELE_forTime(4, 2);   // ON RL4 for 2sec
    }
  }
}


void OnRELE_forTime(int Rele, float Tempo)
{
    if (Rele == 1)
    {
        RL1 = 1;
        wait(Tempo);
        RL1 = 0;
    }

    if (Rele == 2)
    {
        RL2 = 1;
        wait(Tempo);
        RL2 = 0;
    }   

    if (Rele == 3)
    {
        RL3 = 1;
        wait(Tempo);
        RL3 = 0;
    }   

    if (Rele == 4)
    {
        RL4 = 1;
        wait(Tempo);
        RL4 = 0;
    }   
}

IMG_0507.JPG
注:使用的是[size=0.7em]Seeed Studio的继电器盾板
[size=0.7em]Seeed Studio http://wiki.seeedstudio.com/wiki/Main_Page
源程序基于NUCLEO-F334R8

评分

参与人数 1 ST金币 +10 收起 理由
zero99 + 10

查看全部评分

收藏 1 评论7 发布时间:2016-10-20 16:05

举报

7个回答
anywill 回答时间:2016-10-20 16:11:46
先占楼备用
st-nucleo-f401re-morpho.png
NUCL-1.jpg
zero99 回答时间:2016-10-20 16:16:35
厉害
xyx365 回答时间:2016-10-20 18:27:18
好资料,学习中。。。。
mark0668 回答时间:2016-10-20 20:44:52
感谢分享
assssdz 回答时间:2016-10-20 21:02:01
:)
Stm32McuLover 回答时间:2016-10-22 12:51:04
samhong 回答时间:2017-3-17 13:30:42
非常感谢!分享!

所属标签

相似问题

关于意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新和工艺
招聘信息
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
关注我们
st-img 微信公众号
st-img 手机版