2016-06-22 8 views
0

Arduino Projects Bookからこのコードに問題がありました。非常に単純なコードソリーです。Arduino UNOエラー

これは私が書いたコードです:

const int greenLEDpin = 9; 
const int redLEDpin = 10; 
const int blueLEDpin = 11; 

const int redSensorpin = A0; 
const int greenSensorpin = A1; 
const int blueSensorpin = A2; 

int redValue = 0; 
int greenValue = 0; 
int blueValue = 0; 

void setup() { 
    Serial.begin(9600); 

    pinMode(greenLEDpin,OUTPUT); 
    pinMode(redLEDpin,OUTPUT); 
    pinMode(blueLEDpin,OUTPUT); 

} 

void loop() { 

    redSensorValue = analogRead(redSensorpin); 
    delay (5); 
    greenSensorValue = analogRead(greenSensorpin); 
    delay(5); 
    blueSensorValue = analogRead(blueSensorpin); 

    Serial.print("Raw Sensor Values \t Red: "); 
    Serial.print(redSensorValue); 
    Serial.print("\t Green: "); 
    Serial.print(greenSensorValue); 
    Serial.print("\t Blue: "); 
    Serial.println(blueSensorValue); 

    redValue = redSensorValue/4; 
    greenValue = greenSensorValue/4; 
    blueValue = blueSensorValue/4; 

    Serial.print("Mapped Sensor Values \t ReD: "); 
    Serial.print(redValue); 
    Serial.print("\t Green: "); 
    Serial.print(greenValue); 
    Serial.print("\t Blue: "); 
    Serial.print(blueValue); 
    analogWrite(redLEDpin, redValue); 
    analogWrite(greenLEDpin, greenValue); 
    analogWrite(blueLEDpin, blueValue); 
} 

そして、ここではエラーです: アルドゥイーノ:1.7.10(Windowsの8.1)、カタルーニャ: "Arduinoの宇野"

LED_tricolor.ino: In function 'void loop()': 

LED_tricolor.ino:24:2: error: 'redSensorValue' was not declared in this scope 

LED_tricolor.ino:26:2: error: 'greenSensorValue' was not declared in this scope 

LED_tricolor.ino:28:2: error: 'blueSensorValue' was not declared in this scope 

誰かが知っていますここで何が起こっていますか?私は前に変数を置くようなものをいくつか試しましたが、何もしませんでした。 希望の人は私を助けることができます^^。

int redSensorValue = 0; 
int greenSensorValue = 0; 
int blueSensorValue = 0; 

またはご希望の場合は、単にループであなたの変数の名前の前にintを追加することができます。

+0

これらの変数はどこで宣言されていますか? –

+0

宣言はどこですか?あなたは初期化を持っていますが、型の宣言がありません – Li357

答えて

1

だけでセットアップ前にこれを追加してみてください。

0

センサーピンを追加しませんでした。setup()機能にセンサーピンを追加しませんでした。あなたと同じように機能します。

void setup() { 

    pinMode(redSensorpin,INPUT); 
    pinMode(greenSensorpin,INPUT); 
    pinMode(blueSensorpin,INPUT); 

    pinMode(greenLEDpin,OUTPUT); 
    pinMode(redLEDpin,OUTPUT); 
    pinMode(blueLEDpin,OUTPUT); 
    Serial.begin(9600); 

} 
関連する問題