如何消除错误:';串行USB';在我的Arduino草图中没有在此范围内声明?

如何消除错误:';串行USB';在我的Arduino草图中没有在此范围内声明?,arduino,usb,Arduino,Usb,代码如下,从教程中稍作修改。我正在做一个3.1的小游戏。我添加了#include,但没有帮助。我还尝试了SerialUSB.begin(9600)而不是WiredSerial.begin(9600)//在到期时使用本机端口 #include <SoftwareSerial.h> //minimal sketch for connection to ADS129n family. Load this script and open Tools/SerialMonitor. //Yo

代码如下,从教程中稍作修改。我正在做一个3.1的小游戏。我添加了
#include
,但没有帮助。我还尝试了
SerialUSB.begin(9600)而不是W
iredSerial.begin(9600)//在到期时使用本机端口

#include <SoftwareSerial.h>

//minimal sketch for connection to ADS129n family. Load this script and open Tools/SerialMonitor. 
//You should see text like this
//  Device Type (ID Control Register): 62 Channels: 8
//If you see "Channels: 0" then check your wiring
#include "ads1298.h"
#include "adsCMD.h"
#include <Arduino.h>
#include <SPI.h>  // include the SPI library:
int gMaxChan = 0; //maximum number of channels supported by ads129n = 4,6,8
int gIDval = 0; //Device ID : lower 5 bits of  ID Control Register 

int activeSerialPort = 0; //data will be sent to serial port that last sent commands. E.G. bluetooth or USB port
const int kPIN_LED = 13;//pin with in-built light - typically 13, 11 for Teensy 2.0. 

#if defined(__SAM3X8E__)
  #define isDUE  //Detect Arduino Due
  #define WiredSerial SerialUSB //Use Due's Native port
#else  
  #define WiredSerial Serial
#endif

void setup(){
  using namespace ADS1298;
  //prepare pins to be outputs or inputs
  //pinMode(PIN_SCLK, OUTPUT); //optional - SPI library will do this for us
  //pinMode(PIN_DIN, OUTPUT); //optional - SPI library will do this for us
  //pinMode(PIN_DOUT, INPUT); //optional - SPI library will do this for us
  pinMode(IPIN_CS, OUTPUT);
  pinMode(PIN_START, OUTPUT);
  pinMode(IPIN_DRDY, INPUT);
  //pinMode(PIN_CLKSEL, OUTPUT);//*optional
  //pinMode(IPIN_RESET, OUTPUT);//*optional
  //pinMode(IPIN_PWDN, OUTPUT);//*optional
  //start small peripheral interface
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  #ifndef isDUE
  SPI.setClockDivider(SPI_CLOCK_DIV4); //http://forum.pjrc.com/threads/1156-Teensy-3-SPI-Basic-Clock-Questions
  #endif
  SPI.setDataMode(SPI_MODE1);
  //Start ADS1298
  delay(500); //wait for the ads129n to be ready - it can take a while to charge caps
  adc_send_command(SDATAC); // Send SDATAC Command (Stop Read Data Continuously mode)
  delay(10);
  // Determine model number and number of channels available
  gIDval = adc_rreg(ID); //lower 5 bits of register 0 reveal chip type
  switch (gIDval & B00011111 ) { //least significant bits reports channels
          case  B10000: //16
            gMaxChan = 4; //ads1294
            break;
          case B10001: //17
            gMaxChan = 6; //ads1296
            break; 
          case B10010: //18
            gMaxChan = 8; //ads1298
            break;
          case B11110: //30
            gMaxChan = 8; //ads1299
            break;
          default: 
            gMaxChan = 0;
  }
  //start serial port
  SerialUSB.begin(9600); //use native port on Due
  //WiredSerial.begin(9600); //use native port on Due
  while (WiredSerial.read() >= 0) {} //http://forum.arduino.cc/index.php?topic=134847.0
  //while (!WiredSerial) ; //required by Leonardo http://arduino.cc/en/Serial/IfSerial (ads129n requires 3.3v signals, Leonardo is 5v)
  delay(200);  // Catch Due reset problem
  pinMode(kPIN_LED, OUTPUT); 
}

void loop()
{
  WiredSerial.print("Device Type (ID Control Register): "); SerialUSB.print(gIDval); SerialUSB.print(" Channels: "); SerialUSB.println(gMaxChan); 
  digitalWrite(kPIN_LED, HIGH);   // turn the LED on (HIGH is the voltage level)
  if (gMaxChan > 0)
    delay(500); //long pause if OK
  else
    delay(50); //rapid blink if error
  digitalWrite(kPIN_LED, LOW);    // turn the LED off by making the voltage LOW
  delay(500); 
}
#包括
//连接到ADS129n系列的最小草图。加载此脚本并打开Tools/SerialMonitor。
//您应该看到这样的文本
//设备类型(ID控制寄存器):62个通道:8个
//如果您看到“通道:0”,请检查您的接线
#包括“ads1298.h”
#包括“adsCMD.h”
#包括
#包括//包括SPI库:
int-gMaxChan=0//ads129n支持的最大通道数=4,6,8
int-gIDval=0//设备ID:ID控制寄存器的低5位
int activeSerialPort=0//数据将被发送到上次发送命令的串行端口。例如,蓝牙或USB端口
常数int kPIN_LED=13//带内置灯的插销-对于Teensy 2.0,通常为13、11。
#如果已定义(uu SAM3X8E_uuu)
#定义isDUE//检测Arduino到期
#定义WiredSerial SerialUSB//使用Due的本机端口
#否则
#定义WiredSerial序列
#恩迪夫
无效设置(){
使用名称空间ADS1298;
//准备输出或输入引脚
//pinMode(PIN_SCLK,OUTPUT);//可选-SPI库将为我们执行此操作
//pinMode(PIN_-DIN,OUTPUT);//可选-SPI库将为我们执行此操作
//pinMode(PIN_DOUT,INPUT);//可选-SPI库将为我们完成此操作
pinMode(IPIN_CS,输出);
引脚模式(引脚启动、输出);
pinMode(IPIN_DRDY,输入);
//pinMode(PIN_CLKSEL,输出);//*可选
//pinMode(IPIN_复位,输出);//*可选
//pinMode(IPIN_PWDN,输出);/*可选
//启动小型外围接口
SPI.begin();
SPI.Setbitor(MSBFIRST);
#ifndef isDUE
SPI.设置时钟分配器(SPI时钟分配器4)//http://forum.pjrc.com/threads/1156-Teensy-3-SPI-Basic-Clock-Questions
#恩迪夫
SPI.setDataMode(SPI_模式1);
//启动ADS1298
延迟(500);//等待ads129n准备就绪-充电可能需要一段时间
adc_send_命令(SDATAC);//发送SDATAC命令(停止连续读取数据模式)
延迟(10);
//确定可用通道的型号和数量
gIDval=adc_rreg(ID);//寄存器0的低5位显示芯片类型
开关(gIDval&B00011111){//最低有效位报告通道
案例B10000://16
gMaxChan=4;//ads1294
打破
案例B10001://17
gMaxChan=6;//ads1296
打破
案例B10010://18
gMaxChan=8;//ads1298
打破
案例B11110://30
gMaxChan=8;//ads1299
打破
违约:
gMaxChan=0;
}
//启动串行端口
SerialUSB.begin(9600);//在到期时使用本机端口
//WiredSerial.begin(9600);//在到期时使用本机端口
而(WiredSerial.read()>=0){}//http://forum.arduino.cc/index.php?topic=134847.0
//而(!WiredSerial);//是莱昂纳多要求的http://arduino.cc/en/Serial/IfSerial (ads129n需要3.3v信号,莱昂纳多为5v)
延迟(200);//捕获到期重置问题
pinMode(kPIN_发光二极管,输出);
}
void循环()
{
WiredSerial.print(“设备类型(ID控制寄存器):”);SerialUSB.print(gIDval);SerialUSB.print(“通道”);SerialUSB.println(gMaxChan);
digitalWrite(kPIN_LED,高);//打开LED(高是电压电平)
如果(gMaxChan>0)
延迟(500);//如果正常,则长时间暂停
其他的
延迟(50);//错误时快速闪烁
digitalWrite(kPIN_LED,低);//通过降低电压关闭LED
延迟(500);
}

尝试使用
串行
而不是
串行USB
,我在使用Arduino UNO时尝试过