首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Arduino UNO错误

Arduino UNO错误
EN

Stack Overflow用户
提问于 2016-06-23 07:29:08
回答 2查看 341关注 0票数 0

我在Arduino Projects Book中的代码中遇到了一个问题,这是一个非常简单的代码。

这是我写的代码:

代码语言:javascript
复制
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“

代码语言:javascript
复制
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

有人知道这里发生了什么吗?我之前试过一些方法,比如输入变量,但什么也没做。希望你们能帮助我^^。

EN

回答 2

Stack Overflow用户

发布于 2016-07-09 18:02:13

尝试在安装之前添加以下内容:

代码语言:javascript
复制
int redSensorValue = 0; 
int greenSensorValue = 0; 
int blueSensorValue = 0; 

或者,如果您愿意,也可以在循环中的变量名之前添加int

票数 2
EN

Stack Overflow用户

发布于 2017-11-16 14:41:18

您没有在setup()函数中添加任何传感器引脚。就像这样编辑你的函数。

代码语言:javascript
复制
void setup() {

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

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

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37979863

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档