簡體   English   中英

Arduino UNO錯誤

[英]Arduino UNO error

我從Arduino Projects Book那里得到了這個代碼的問題,如果很討厭的話,這是一個非常簡單的代碼。

這是我寫的代碼:

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);
}

這是錯誤:Arduino:1.7.10(Windows 8.1),Placa:“ Arduino Uno”

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

您沒有在setup()函數中添加任何傳感器引腳。 像這樣編輯您的功能。

void setup() {

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

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

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM