"读"没有命名类型

时间:2015-07-02 04:03:37

标签: c++ arduino libraries monitor

我一直在编写一个程序,要求我从Arduino的串行监视器中获取输入。但是我遇到了一些问题。这是我的代码。更新:这是我在几次修订后创建的新代码。

#include <SoftwareSerial.h>

int R1 = 20;
int R2_2 = 20;
int R4_7 = 20;
int R5_6 = 20;
int R7_5 = 20;
int R8_2 = 20;
int R10 = 22;
int R15 = 20;
int R22 = 20;
int R27 = 20;
int R33 = 22;
int R39 = 20;
int R47 = 20;
int R56 = 20;
int R68 = 20;
int R75 = 20;
int R82 = 20;
int R100 = 20;
int R120 = 20;
int R150 = 20;
int R180 = 20;
int R220 = 20;
int R270 = 20;
int R330 = 20;
int R390 = 20;
int R470 = 20;
int R510 = 20;
int R680 = 20;
int R820 = 20;
int R1K = 20;
int R1K5 = 20;
int R2K2 = 20;
int R3K3 = 20;
int R3K9 = 20;
int R4K7 = 20;
int R5K6 = 20;
int R6K8 = 20;
int R7K5 = 20;
int R8K2 = 20;
int R10K = 20;
int R15K = 20;
int R22K = 20;
int R33K = 20;
int R39K = 20;
int R47K = 20;
int R56K = 20;
int R68K = 20;
int R75K = 20;
int R82K = 20;
int R100K = 20;
int R150K = 20;
int R180K = 20;
int R220K = 20;
int R330K = 20;
int R470K = 20;
int R560K = 20;
int R680K = 20;
int R1M = 20;
int R1M5 = 20;
int R2M = 20;
int R3M3 = 20;
int R4M7 = 20;
int R5M6 = 20;
int R10M = 20;
int Resistors = R1 + R2_2 + R4_7 + R5_6 + R7_5 + R8_2 + R10 + R15 + R22     + R27 + R33 + R39 + R47 + R56 + R68 + R75 + R82 + R100 + R120 + R150 + R180 + R220 + R270 + R330 + R390 + R470 + R510 + R680 + R820 + R1K + R1K5 + R2K2 + R3K3 + R3K9 + R4K7 + R5K6 + R6K8 + R7K5 + R8K2 + R10K + R15K + R22K + R33K + R39K + R47K + R56K + R68K + R75K + R82K + R100K + R150K + R180K + R220K + R330K + R470K + R560K + R680K + R1M + R1M5 + R2M + R3M3 + R4M7 + R5M6 + R10M;
int AClips = 11;
int Blue_LED = 50;
int RGB_LED = 1;
int Yellow_LED = 10;
int Red_LED = 16;
int Button = 102;
int Carbon_Film = 2;
int Ambient_Light_Sensor = 10;
int Laser_Diode = 9;
int photocell = 1;
int Piezo_Buzzer = 1;
int Relay = 1;
int Transistor_2N2222A = 1;
int Transistors = 0 + Transistor_2N2222A;
int Servo = 1;
int Diode_1N4148 = 2;
int Diodes = Diode_1N4148;

//This next line is the line that was highlighted
read.Serial(searchedItem);

void setup() {
//setup code here, to run once:
Serial.begin(9600);
}

void loop() {
//loop code here, to run forever:
if (Serial.available() > 0) {
  // read the incoming byte:
  searchedItem = Serial.read();
  //Code here
  if (searchedItem == "Red LED", "red led", "Red led") {
    searchedItem = Red_LED;
    if (searchedItem => 1) {
     Serial.println("\nFound!\nYou have ", Red_LED, "Red LEDs");
      }
    }
  }
}

2 个答案:

答案 0 :(得分:0)

您的代码不在函数中。你不能这样做,这就是为什么这条线被“突出显示”。

答案 1 :(得分:0)

此代码不在任何函数内:

read.Serial(searchedItem);

此外,该函数为Serial.read。您需要确保缓冲区中有可用数据Serial.available()loop()内尝试类似的内容:

if (Serial.available() > 0) {
    // read the incoming byte:
    incomingByte = Serial.read();
    //Your code here
}