Skip to main content
added 13 characters in body
Source Link
Bubo
  • 818
  • 4
  • 19
  • 35

I am trying to write a simple library for an Arduino to parse and interpret serial commands. my goal with the example library is to read the expected command and turn on some LEDs. I have gotten serial communications to work via the arduino, and I want it to be handled by a library. For Example...I have the following code on my arduino

Arduino Code:

#include <serialComms.h>
serialComms testing = serialComms();
void setup()
{
 Serial.begin(9600); 
}

void loop() // not terribly concerned with the main loop, only the serialEvent, which I        have tested and works
{

}


void serialEvent()
{
   testing.readbytesreadNewBytes();
   testing.assignBytes();
}

serialComms.cpp

#include <Arduino.h>
#include <serialComms.h>

void serialComms::init()
{
  // This is where the constructor would be...right now we are too stupid to have one
}

void serialComms::readBytesreadNewBytes()  // Target Pin,Values
{
        digitalWrite(11,HIGH);
        delay(250);
        digitalWrite(11,LOW);
        assignBytes();

}

void serialComms::assignBytes()
{
    for(int t  = 0;t<5;t++)
    {
        digitalWrite(10,HIGH);
        delay(250);
        digitalWrite(10,LOW);
    }   
   }

serialComms.h

#ifndef serialCommsserialComms_h
#define serialCommsserialComms_h



/* serialComms Class */
class serialComms
{
  public:
    serialComms() {};
    void init();
    void readBytesreadNewBytes(); // Will be used to create the array --> two variables for now...
    void assignBytes();
    };

#endif

My questions are as follows...

1.) Do I have the libraries structured properly? I just want the LEDs to blink when I send a message and trigger the serialEvent, When I run the code in arduino I get the following errors.

testingLibraries:2: error: 'serialComms' does not name a type
testingLibraries.ino: In function 'void serialEvent()':
testingLibraries:16: error: 'testing' was not declared in this scope

I have the .cpp and .h file in a folder named serialComms in the libraries folder. I am not really sure where to go from here, any thoughts?

I am trying to write a simple library for an Arduino to parse and interpret serial commands. my goal with the example library is to read the expected command and turn on some LEDs. I have gotten serial communications to work via the arduino, and I want it to be handled by a library. For Example...I have the following code on my arduino

Arduino Code:

#include <serialComms.h>
serialComms testing = serialComms();
void setup()
{
 Serial.begin(9600); 
}

void loop() // not terribly concerned with the main loop, only the serialEvent, which I        have tested and works
{

}


void serialEvent()
{
   testing.readbytes();
   testing.assignBytes();
}

serialComms.cpp

#include <Arduino.h>
#include <serialComms.h>

void serialComms::init()
{
  // This is where the constructor would be...right now we are too stupid to have one
}

void serialComms::readBytes()  // Target Pin,Values
{
        digitalWrite(11,HIGH);
        delay(250);
        digitalWrite(11,LOW);
        assignBytes();

}

void serialComms::assignBytes()
{
    for(int t  = 0;t<5;t++)
    {
        digitalWrite(10,HIGH);
        delay(250);
        digitalWrite(10,LOW);
    }   
   }

serialComms.h

#ifndef serialComms
#define serialComms



/* serialComms Class */
class serialComms
{
  public:
    serialComms() {};
    void init();
    void readBytes(); // Will be used to create the array --> two variables for now...
    void assignBytes();
    };

#endif

My questions are as follows...

1.) Do I have the libraries structured properly? I just want the LEDs to blink when I send a message and trigger the serialEvent, When I run the code in arduino I get the following errors.

testingLibraries:2: error: 'serialComms' does not name a type
testingLibraries.ino: In function 'void serialEvent()':
testingLibraries:16: error: 'testing' was not declared in this scope

I have the .cpp and .h file in a folder named serialComms in the libraries folder. I am not really sure where to go from here, any thoughts?

I am trying to write a simple library for an Arduino to parse and interpret serial commands. my goal with the example library is to read the expected command and turn on some LEDs. I have gotten serial communications to work via the arduino, and I want it to be handled by a library. For Example...I have the following code on my arduino

Arduino Code:

#include <serialComms.h>
serialComms testing = serialComms();
void setup()
{
 Serial.begin(9600); 
}

void loop() // not terribly concerned with the main loop, only the serialEvent, which I        have tested and works
{

}


void serialEvent()
{
   testing.readNewBytes();
   testing.assignBytes();
}

serialComms.cpp

#include <Arduino.h>
#include <serialComms.h>

void serialComms::init()
{
  // This is where the constructor would be...right now we are too stupid to have one
}

void serialComms::readNewBytes()  // Target Pin,Values
{
        digitalWrite(11,HIGH);
        delay(250);
        digitalWrite(11,LOW);
        assignBytes();

}

void serialComms::assignBytes()
{
    for(int t  = 0;t<5;t++)
    {
        digitalWrite(10,HIGH);
        delay(250);
        digitalWrite(10,LOW);
    }   
   }

serialComms.h

#ifndef serialComms_h
#define serialComms_h



/* serialComms Class */
class serialComms
{
  public:
    serialComms() {};
    void init();
    void readNewBytes(); // Will be used to create the array --> two variables for now...
    void assignBytes();
    };

#endif

My questions are as follows...

1.) Do I have the libraries structured properly? I just want the LEDs to blink when I send a message and trigger the serialEvent, When I run the code in arduino I get the following errors.

testingLibraries:2: error: 'serialComms' does not name a type
testingLibraries.ino: In function 'void serialEvent()':
testingLibraries:16: error: 'testing' was not declared in this scope

I have the .cpp and .h file in a folder named serialComms in the libraries folder. I am not really sure where to go from here, any thoughts?

Source Link
Bubo
  • 818
  • 4
  • 19
  • 35

Writing Libraries for Arduino

I am trying to write a simple library for an Arduino to parse and interpret serial commands. my goal with the example library is to read the expected command and turn on some LEDs. I have gotten serial communications to work via the arduino, and I want it to be handled by a library. For Example...I have the following code on my arduino

Arduino Code:

#include <serialComms.h>
serialComms testing = serialComms();
void setup()
{
 Serial.begin(9600); 
}

void loop() // not terribly concerned with the main loop, only the serialEvent, which I        have tested and works
{

}


void serialEvent()
{
   testing.readbytes();
   testing.assignBytes();
}

serialComms.cpp

#include <Arduino.h>
#include <serialComms.h>

void serialComms::init()
{
  // This is where the constructor would be...right now we are too stupid to have one
}

void serialComms::readBytes()  // Target Pin,Values
{
        digitalWrite(11,HIGH);
        delay(250);
        digitalWrite(11,LOW);
        assignBytes();

}

void serialComms::assignBytes()
{
    for(int t  = 0;t<5;t++)
    {
        digitalWrite(10,HIGH);
        delay(250);
        digitalWrite(10,LOW);
    }   
   }

serialComms.h

#ifndef serialComms
#define serialComms



/* serialComms Class */
class serialComms
{
  public:
    serialComms() {};
    void init();
    void readBytes(); // Will be used to create the array --> two variables for now...
    void assignBytes();
    };

#endif

My questions are as follows...

1.) Do I have the libraries structured properly? I just want the LEDs to blink when I send a message and trigger the serialEvent, When I run the code in arduino I get the following errors.

testingLibraries:2: error: 'serialComms' does not name a type
testingLibraries.ino: In function 'void serialEvent()':
testingLibraries:16: error: 'testing' was not declared in this scope

I have the .cpp and .h file in a folder named serialComms in the libraries folder. I am not really sure where to go from here, any thoughts?