내 코드가 부족하다는 것을 알고 싶습니다. 아두 이노 컴파일러, IDE 버전 1.8.0이 오류가 발생Arduino 여러 파일 개체 범위
'swSerial' was not declared in this scope
코드는 "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