Ich würde gerne wissen, was in meinem Code fehlt. Die Arduino-Compiler, IDE Version 1.8.0, erzeugt diesen Fehler:Arduino mehrere Datei Objektbereich
'swSerial' was not declared in this scope
Der Code diese drei Dateien, die in einem Ordner enthalten, werden als "object_scope".
// object_scope.ino
//
#include <SoftwareSerial.h>
#include "mylib.h"
const byte rxPin = 2;
const byte txPin = 3;
SoftwareSerial swSerial (rxPin, txPin);
void setup() {
swSerial.begin(9600);
swSerial.println("Hello");
printSum(4, 5);
}
void loop() {
}
// mylib.cpp
//
#include "mylib.h"
void printSum(int a, int b) {
int sum = a+b;
swSerial.println (sum);
// generates error "'swSerial' was not declared in this scope"
}
// mylib.h
//
#ifndef mylib_h
#define mylib_h
void printSum(int a, int b);
#endif