Laporan
Sistem Manufaktur Terpadu
Timer pada Traffic
Light
Studi
Kasus Traffic Light pada Siwalankerto, Surabaya
Listing
Program
1.
widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include
namespace Ui {
class
Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
private:
Ui::Widget *ui;
private slots:
void
update();
void
on_pushButton_clicked();
};
#endif // WIDGET_H
2.
main.cpp
#include
#include "widget.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
3.
widget.cpp
#include
"widget.h"
#include "ui_widget.h"
#include "QTimer"
#include "QSound"
int a=16,kuning=3,merah=12;
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start(1000);
}
Widget::~Widget()
{
delete ui;
}
void Widget::update()
{
if(a<=3)
{
ui->label->setPixmap(QPixmap("C:/Users/EVAN/Pictures/New
folder/yellow.png"));
ui->label_2->setPixmap(QPixmap("C:/Users/EVAN/Pictures/New
folder/yellow.png"));
ui->lcdNumber->display(kuning);
kuning--;
QSound::play("C:/Users/EVAN/Downloads/Music/sirentone.wav");
}
else
if(a<=15)
{ kuning=3;
ui->label->setPixmap(QPixmap("C:/Users/EVAN/Pictures/New
folder/11949849771043985234traffic_light_red_dan_ge_01.svg.med.png"));
ui->label_2->setPixmap(QPixmap("C:/Users/EVAN/Pictures/New
folder/11949849761176136192traffic_light_green_dan__01.svg.med.png"));
ui->lcdNumber->display(merah);
merah--;
QSound::play("C:/Users/EVAN/Downloads/Music/sirentone_2.wav");
}
else
{ merah=11;
ui->label->setPixmap(QPixmap("C:/Users/EVAN/Pictures/New
folder/11949849761176136192traffic_light_green_dan__01.svg.med.png"));
ui->label_2->setPixmap(QPixmap("C:/Users/EVAN/Pictures/New
folder/11949849771043985234traffic_light_red_dan_ge_01.svg.med.png"));
}
a++;
}
void Widget::on_pushButton_clicked()
{
a=0;
}