ความรู้แน่น ฟรีสำหรับชุมชน ArduinoAll ที่นี่เท่านั้น

ฟรีและดีที่สุด คอร์สอบรม Arduino + NodeMCU
ทำเพื่อแบ่งปัน ห้ามนำไปจำหน่าย หรือเก็บเงินค่าเรียน
  !!!


  


AllNewStep รับประกันคุณภาพทุกชิ้น วันจันทร์-ศุกร์แจ้งชำระสินค้าก่อน 14.00 จัดส่งทันทีวันนี้ค่ะ

กรุงเทพ /ภาคกลาง ได้พรุ่งนี้


*** สินค้าทุกชิ้น ถ้าสามารถทำรายการสั่งซื้อได้ แสดงว่ามีครบทุกรายการค่ะ *** 

พิมพ์ค้นหาบทความ หัวข้อกระทู้ และสินค้าในเว็บ AllNewStep ได้ที่นี่
QUOTE 

จะให้ค่าตัวเลข DO ในโค้ดนี้แสดงออกจอ LCD ได้ยังไง มันขึ้นค่าตัวเลขแค่ใน serial monitor

Max Photsathorn

//This code was written to be easy to understand.

//Modify this code as you see fit.

//This code will output data to the Arduino serial monitor.

//Type commands into the Arduino serial monitor to control the D.O. circuit.

//This code was written in the Arduino 1.8.3 IDE

//An Arduino UNO was used to test this code.

//This code was last tested 6/2017

#include <LiquidCrystal.h>

#include <SoftwareSerial.h>                           //we have to include the SoftwareSerial library, or else we can't use it

#define rx 2                                          //define what pin rx is going to be

#define tx 3                                          //define what pin tx is going to be

#define PUMP 4 

SoftwareSerial myserial(rx, tx);                      //define how the soft serial port is going to work

LiquidCrystal lcd(12, 11, 4, 5, 6, 7);

String inputstring = "";                              //a string to hold incoming data from the PC

String sensorstring = "";                             //a string to hold the data from the Atlas Scientific product

boolean input_string_complete = false;                //have we received all the data from the PC

boolean sensor_string_complete = false;               //have we received all the data from the Atlas Scientific product

                                         //used to hold a floating point number that is the DO

 

 

void setup() {                                        //set up the hardware

  Serial.begin(9600);                                 //set baud rate for the hardware serial port_0 to 9600

  myserial.begin(9600);                               //set baud rate for the software serial port to 9600

  inputstring.reserve(10);                            //set aside some bytes for receiving data from the PC

  sensorstring.reserve(30);   

   pinMode(PUMP, OUTPUT);

  lcd.begin(16, 2);

  lcd.print("DO: ");

    

}

 

 

 

void serialEvent() {                                  //if the hardware serial port_0 receives a char

  inputstring = Serial.readStringUntil(13);           //read the string until we see a <CR>

  input_string_complete = true;                       //set the flag used to tell if we have received a completed string from the PC 

}

 

 

void loop() {                                         //here we go...

float DO; 

  if (input_string_complete){                         //if a string from the PC has been received in its entirety

    myserial.print(inputstring);                      //send that string to the Atlas Scientific product

    myserial.print('\r');                             //add a <CR> to the end of the string 

    inputstring = "";                                 //clear the string

    input_string_complete = false;                    //reset the flag used to tell if we have received a completed string from the PC

  }

 

  if (myserial.available() > 0) {                     //if we see that the Atlas Scientific product has sent a character

    char inchar = (char)myserial.read();              //get the char we just received

    sensorstring += inchar;                           //add the char to the var called sensorstring

    if (inchar == '\r') {                             //if the incoming character is a <CR>

      sensor_string_complete = true;                  //set the flag

    }

  }

 

  if (sensor_string_complete== true) {                //if a string from the Atlas Scientific product has been received in its entirety

    Serial.println(sensorstring);                     //send that string to the PC's serial monitor

                                                 //uncomment this section to see how to convert the DO reading from a string to a float 

    if (isdigit(sensorstring[0])) {                   //if the first character in the string is a digit

      DO = sensorstring.toFloat();                    //convert the string to a floating point number so it can be evaluated by the Arduino

      if (DO >= 9.62) {                                //if the DO is greater than or equal to 6.0

        digitalWrite(PUMP,HIGH);//print "high" this is demonstrating that the Arduino is evaluating the DO as a number and not as a string

      }

      if (DO <= 9.59) {                               //if the DO is less than or equal to 5.99

       digitalWrite(PUMP,LOW);//ating that the Arduino is evaluating the DO as a number and not as a string

      }

    }

    

    sensorstring = "";                                //clear the string

    sensor_string_complete = false;                   //reset the flag used to tell if we have received a completed string from the Atlas Scientific product

  }

}

 

QUOTE 
ความคิดเห็นที่ #1
เจ้าของร้าน

การใช้งานจอ LCD แบบละเอียด มีในคอร์สสอน Arduino Starter ที่หน้าเว็บ ฟรีครับ 

 

QUOTE 
ความคิดเห็นที่ #2
Max Photsathorn
ขอบคุณมากๆคับ ขอลิ้งเว็บ Arduino Starter น่อยคับหาไม่เจอ
QUOTE 
ความคิดเห็นที่ #3
เจ้าของร้าน

ที่บนสุดของทุกหน้าครับ

แสดงความคิดเห็นที่ 1-3 จากทั้งหมด 3 ความคิดเห็น
ขาย ARDUINO
คุณภาพ อันดับ 1

ได้รับรางวัลร้านยอดเยี่ยม
ตั้งแต่ปี 2558
ขาย Arduino
วีดีโอสอน Arduino

สอน esp8266

สอน Arduino IoT
สอน Arduino แบบเร็ว

สอน NodeMCU

อุปกรณ์ Arduino

MEMBER ZONE

พูดคุย-สอบถาม