樹莓派+PCF8591--03--pwm輸出
阿新 • • 發佈:2018-12-16
mainwindow.h
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include<wiringPi.h> #include<pcf8591.h> #define Address 0x48 #define BASE 64 #define A0 BASE+0 #define A1 BASE+1 #define A2 BASE+2 #define A3 BASE+3 namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); private slots: void on_pushButton_clicked(); private: Ui::MainWindow *ui; }; #endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); wiringPiSetup(); pcf8591Setup(BASE,Address); ui->horizontalSlider->setMaximum(255); ui->horizontalSlider->setMinimum(0); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_clicked() { analogWrite(A0,ui->horizontalSlider->value()); }
ui上一個Button一個horizontal slider
記著.pro中的
LIBS+= -lwiringPi