Main Menu
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - pacozaa

#49
char inData[20]; // Allocate some space for the string
char inChar=-1; // Where to store the character read
byte index = 0; // Index into array; where to store the character

void setup() {
    Serial.begin(9600);
    Serial.write("Power On");
}

char Comp(char* This) {
    while (Serial.available() > 0) // Don't read unless
                                   // there you know there is data
    {
        if(index < 19) // One less than the size of the array
        {
            inChar = Serial.read(); // Read a character
            inData[index] = inChar; // Store it
            index++; // Increment where to write next
            inData[index] = '\0'; // Null terminate the string
        }
    }

    if (strcmp(inData,This)  == 0) {
        for (int i=0;i<19;i++) {
            inData[i]=0;
        }
        index=0;
        return(0);
    }
    else {
        return(1);
    }
}

void loop()
{
    if (Comp("m1 on")==0) {
        Serial.write("Motor 1 -> Online\n");
    }
    if (Comp("m1 off")==0) {
        Serial.write("Motor 1 -> Offline\n");
    }
}


อยากทราบว่าโปรแกรมนี้ทำงานยังไงน่ะครับ
http://stackoverflow.com/questions/5697047/convert-serial-read-into-a-useable-string-using-arduino


ผมไม่เข้าใจอยู่สองจุดครับ

char Comp(char* This) ทำงานยังไงครับ
(strcmp(inData,This)  == 0) ทำงานยังไงครับ
ถ้าเป็นไปได้รบกวนอธิบายโปรแกรมโดยรวมให้หน่อยครับ
#50
ลองดูแล้วครับ ไม่ได้ผลครับ  เดี๋ยวเปลี่ยนไปใช้pin ธรรมดาแล้วครับ ขอบคุณมากครับ

คราวหน้าผมค่อยเปลี่ยนไปใช้ PCF น่ะครับ
#51
คอมไพล์ผ่านแล้วครับ
แต่ว่าLCD ติดสว่างทุก pixel เฉยๆ ครับ ไม่ได้แสดงตัวอักษรออกมาครับ

แก้ไขที่ตรงไหนดีครับ
#52
ของผมเวอร์ชัน Arduino 1.0 ครับ

ตามรูปเป็นเวอร์ชันเก่ากว่าครับ
#53



ผมใช้ Arduino MEGA 2560 จะควบคุม LCD 20x4 ผ่าน I2C โดยใช้ IC mcp23008  จากโมดูลตัวนี้ครับ
http://www.arduino.in.th/product/127/i2c-convertor-module-for-lcd1602-2004
ใช้ Arduino 1.0
ลองใช้ Library จากลิงค์นี้ดู
http://playground.arduino.cc/Code/I2CPortExpanderAndLCDs
แล้วcompile ไม่ผ่านครับ ลองแก้ส่วนของโปรแกรมแล้วนะครับ
"WConstants.h" เป็น "Arduino.h"
Wire.send เป็น Wire.write


ขึ้น Error ตามรูปนี้ครับ
#54
รายงานตัวด้วยคนคร้าบบ