由于初学,实在看不出来到底为什么老是编译失败,求各位大神的指导
主程序代码:
#include"Light.h"
#include"Arduino.h"
Light light(13,11,12);
void setup() {
}
void loop() {
light.on("Pink");
}
Light.h
#ifndef Light_h
#define Light_h
#include"Arduino.h"
class Light{
public:
Light(int R,int G,int B);
void on(char on[]);
void off();
void self(int Ranalog,int Ganalog,int Banalog);
private:
int Red;
int Blue;
int Green;
};
#endif
Light.cpp
#include"Arduino.h"
#include"Light.h"
Light::Light(int R,int G,int B){
int Red=R;
int Blue=B;
int Green=G;
pinMode(Red,OUTPUT);
pinMode(Blue.OUTPUT);
pinMode(Green,OUTPUT);
}
void Light::on(char on[]){
if(on[0]=="R"){
digitalWrite(Red,HIGH);
digitalWrite(Blue,LOW);
digitalWrite(Green,LOW);
}
if(on[0]=="G"){
digitalWrite(Red,LOW);
digitalWrite(Blue,LOW);
digitalWrite(Green,HIGH);
}
if(on[0]=="B"){
digitalWrite(Red,LOW);
digitalWrite(Blue,HIGH);
digitalWrite(Green,LOW);
}
if(on[0]=="Y"){
digitalWrite(Red,HIGH);
digitalWrite(Blue,LOW);
digitalWrite(Green,HIGH);
}
if(on[0]=="P"){
digitalWrite(Red,HIGH);
digitalWrite(Blue,HIGH);
digitalWrite(Green,LOW);
}
if(on[0]=="C"){
digitalWrite(Red,LOW);
digitalWrite(Blue,HIGH);
digitalWrite(Green,HIGH);
}
if(on[0]=="W"){
digitalWrite(Red,HIGH);
digitalWrite(Blue,HIGH);
digitalWrite(Green,HIGH);
}
}
void Light::off(){
digitalWrite(Red,LOW);
digitalWrite(Blue,LOW);
digitalWrite(Green,LOW);
}
void Light::self(int Ranalog,int Ganalog,int Banalog){
if(Red!=11||Red!=10||Red!=9||Red!=6||Red!=5||Red!=3){
if(Ranalog<=512){
digitalWrite(Red,LOW);
}
else{
digitalWrite(Red,HIGH);
}
}
else{
analogWrite(Red,Ranalog);
}
if(Blue!=11||Blue!=10||Blue!=9||Blue!=6||Blue!=5||Blue!=3){
if(Banalog<=512){
digitalWrite(Blue,LOW);
}
else{
digitalWrite(Blue,HIGH);
}
}
else{
analogWrite(Blue,Banalog);
}
if(Green!=11||Green!=10||Green!=9||Green!=6||Green!=5||Green!=3){
if(Ganalog<=512){
digitalWrite(Green,LOW);
}
else{
digitalWrite(Green,HIGH);
}
}
else{
analogWrite(Green,Ganalog);
}
}
|