Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to control LED luminosity by entering number in Qt to Arduino
Forum Updated to NodeBB v4.3 + New Features

How to control LED luminosity by entering number in Qt to Arduino

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Macive XiongM Offline
    Macive XiongM Offline
    Macive Xiong
    wrote on last edited by
    #1

    Hi everyone, I am a new learner of Qt. Recently, I am trying to develop a GUI to control the luminosity of LED thru Arduino by typing number (0~255) in Qt GUI.

    Here is my Arduino code:

    const int ledPin = 9;
    int ledlum;
    
    void setup() {
      pinMode(ledPin, OUTPUT);
      analogWrite(ledPin, 0);
      Serial.begin(9600);
    }
    
    void loop() {
      if (Serial.available()){
       ledlum = Serial.parseInt();
       write_led(ledlum);
    }
    }
    
    void write_led(int lum){
      analogWrite(ledPin, 0 + lum);
     
    }
    
    

    My question is, how can I create a textbox or any box for number input to enter the number to control luminosity? I already know how to connect between Arduino and Qt. The part I don't know is, what's the code for textbox to send number from Qt to Arduino?
    Thank you guys in advance:)

    jsulmJ 1 Reply Last reply
    0
    • Macive XiongM Macive Xiong

      Hi everyone, I am a new learner of Qt. Recently, I am trying to develop a GUI to control the luminosity of LED thru Arduino by typing number (0~255) in Qt GUI.

      Here is my Arduino code:

      const int ledPin = 9;
      int ledlum;
      
      void setup() {
        pinMode(ledPin, OUTPUT);
        analogWrite(ledPin, 0);
        Serial.begin(9600);
      }
      
      void loop() {
        if (Serial.available()){
         ledlum = Serial.parseInt();
         write_led(ledlum);
      }
      }
      
      void write_led(int lum){
        analogWrite(ledPin, 0 + lum);
       
      }
      
      

      My question is, how can I create a textbox or any box for number input to enter the number to control luminosity? I already know how to connect between Arduino and Qt. The part I don't know is, what's the code for textbox to send number from Qt to Arduino?
      Thank you guys in advance:)

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Macive-Xiong You can use QSpinBox to enter a number. Use QSpinBox::value() to get its value.
      See http://doc.qt.io/qt-5/qspinbox.html

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      Macive XiongM 1 Reply Last reply
      2
      • Macive XiongM Offline
        Macive XiongM Offline
        Macive Xiong
        wrote on last edited by
        #3

        @jsulm thank you so much for your help:)

        1 Reply Last reply
        0
        • jsulmJ jsulm

          @Macive-Xiong You can use QSpinBox to enter a number. Use QSpinBox::value() to get its value.
          See http://doc.qt.io/qt-5/qspinbox.html

          Macive XiongM Offline
          Macive XiongM Offline
          Macive Xiong
          wrote on last edited by
          #4

          @jsulm Do you know any example for sending number to Arduino from Qt? I am not really sure how to write the code in Qt to send signal to Arduino thru SpinBox.

          Thank you so much:)

          jsulmJ 1 Reply Last reply
          0
          • Macive XiongM Macive Xiong

            @jsulm Do you know any example for sending number to Arduino from Qt? I am not really sure how to write the code in Qt to send signal to Arduino thru SpinBox.

            Thank you so much:)

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Macive-Xiong No, I don't. How do you communicate with Arduino? Via serial port? If so then take a look at http://doc.qt.io/qt-5/qtserialport-index.html
            In your first post in this thread you actually already have code to communicate with Arduino. I'm not sure what the problem is: get the value from QSpinBox calling its value() method. You can even use http://doc.qt.io/qt-5/qspinbox.html#valueChanged signal to get notified about a new value and then send it to Arduino.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            Macive XiongM 1 Reply Last reply
            0
            • jsulmJ jsulm

              @Macive-Xiong No, I don't. How do you communicate with Arduino? Via serial port? If so then take a look at http://doc.qt.io/qt-5/qtserialport-index.html
              In your first post in this thread you actually already have code to communicate with Arduino. I'm not sure what the problem is: get the value from QSpinBox calling its value() method. You can even use http://doc.qt.io/qt-5/qspinbox.html#valueChanged signal to get notified about a new value and then send it to Arduino.

              Macive XiongM Offline
              Macive XiongM Offline
              Macive Xiong
              wrote on last edited by
              #6

              @jsulm Thanks again for these info. I appreciate it:)

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved