找回密码
 立即注册
收起左侧

button键实现led闪烁 程序无法实现

5
回复
8336
查看
[复制链接]
累计签到:47 天
连续签到:1 天
来源: 2016-5-30 09:06:21 显示全部楼层 |阅读模式
1Qter豆
#include "myqt.h"
#include "ui_myqt.h"

extern "C"
#include "led.h"
Myqt::Myqt(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Myqt)
{


    ui->setupUi(this);
}

Myqt::~Myqt()
{
    delete ui;
}
void Delay(int t)
{
   int i;
   for(;t>0;t--);
    //for(i=0;i<4000;i++);
}
void Myqt:1()
{

  while(1)
  {
           ledctl(1,0);
             Delay(1000);

           ledctl(0,0);
            Delay(1000);
  }
}
不加延迟的时候点击button键led灯瞬间亮灭,但是加延迟后led灯一直保持点亮的状态,但是超级终端显示一直再进行点亮熄灭循环,求大神,如何解决问题!

回复

使用道具 举报

累计签到:595 天
连续签到:1 天
2016-5-30 12:00:19 显示全部楼层
你都用上qt这么高大上的东西了,还用delay这种方式?
给你个实例,我没法点灯,就用一个label来显示红色,蓝色代替了
有用代码
.h
    QTimer *timer;
    bool shine;
public slots:
    void PushButtonFlicker();
    void TimerSlot();


.cpp
    shine = true;
    timer = new QTimer(this);
    connect(timer,SIGNAL(timeout()),this,SLOT(TimerSlot()));
    connect(ui->pushButtonFlicker,SIGNAL(clicked()),this,SLOT(PushButtonFlicker()));


void Dialog:ushButtonFlicker()
{
    timer->start(1000);

}

void Dialog::TimerSlot()
{

    if(shine)
    {
        ui->labelFlicker->setStyleSheet("background-color: rgb(255, 0, 0)");
    }
    else
    {
        ui->labelFlicker->setStyleSheet("background-color: rgb(0, 0, 255)");
    }
    shine = !shine;
}

点评

点了按钮后,开始红蓝闪烁,我切换的时间是1秒  详情 回复 发表于 2016-5-30 12:01
回复

使用道具 举报

累计签到:595 天
连续签到:1 天
2016-5-30 12:01:37 显示全部楼层
sywh 发表于 2016-5-30 12:00
你都用上qt这么高大上的东西了,还用delay这种方式?
给你个实例,我没法点灯,就用一个label来显示红色, ...


点了按钮后,开始红蓝闪烁,我切换的时间是1秒

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

累计签到:47 天
连续签到:1 天
2016-6-1 09:03:13 显示全部楼层
sywh 发表于 2016-5-30 12:01
点了按钮后,开始红蓝闪烁,我切换的时间是1秒

谢谢,问题已经解决了!换了个usleep()函数
回复

使用道具 举报

累计签到:191 天
连续签到:1 天
2016-6-1 21:42:15 显示全部楼层
C51风格的延时程序
回复

使用道具 举报

累计签到:47 天
连续签到:1 天
2016-6-2 09:12:17 显示全部楼层
Youji 发表于 2016-6-1 21:42
C51风格的延时程序

让你见笑了,水平有点LOW
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

公告
可以关注我们的微信公众号yafeilinux_friends获取最新动态,或者加入QQ会员群进行交流:190741849、186601429(已满) 我知道了