C ++ - ' ShiftOut'没有命名类型。 - 在Arduino SDK中编译很好,而不是模拟器

时间:2015-12-02 03:00:25

标签: c++ arduino

我正在整理4x4x4 LED立方体的代码。我遇到的问题是我还没有建立立方体,所以我使用的是模拟器(123D Circuits)。它是一个功能齐全的模拟器,但它非常多而且迟钝。我的问题可能是因为它因为代码在实际的Arduino SDK中编译得很好,但是我想签到。代码如下。

class ShiftOut
{
  public:
    int latchPin;
    int clockPin;
    int dataPin;

    ShiftOut(int, int, int);
    void doWrite(int[], int[], int);
    void doWrite(int, int);
};

ShiftOut::ShiftOut(int lP, int cP, int dP)
{
  latchPin = lP;
  clockPin = cP;
  dataPin = dP;

  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
}

void ShiftOut::doWrite(int pins[], int states[], int length)
{
  byte bits = 0;
  digitalWrite(latchPin, LOW);

  for (int i = 0; i < length; i ++)
  {
    bitWrite(bits, pins[i], states[i]);
  }

  shiftOut(dataPin, clockPin, MSBFIRST, bits);
  digitalWrite(latchPin, HIGH);
}

void ShiftOut::doWrite(int pin, int state)
{
  int pins[] = { pin };
  int states[] = { state };
  int length = 1;
  doWrite(pins, states, length);
}

class PinObject
{
  public:
    int pin;
    int state;
    bool isShifted;
    ShiftOut* shift;

    PinObject(int);
    PinObject(ShiftOut*, int);
    void setState(int);
    int toggle();

    int getPin() {
      return pin;
    }
    int getState() {
      return state;
    }
    bool isShiftPin() {
      return isShifted;
    }
    ShiftOut* getShift() {
      return shift;
    }
};

PinObject::PinObject(int p)
{
  pin = p;
  state = LOW;
  isShifted = false;

  pinMode(p, OUTPUT);
}

PinObject::PinObject(ShiftOut* sO, int p)
{
  shift = sO;
  pin = p;
  state = LOW;
  isShifted = true;
}

void PinObject::setState(int s)
{
  state = s;

  if (isShifted)
    shift->doWrite(pin, state);
  else
    digitalWrite(pin, state);
}

int PinObject::toggle()
{
  setState(1 - state);
  return state;
}

ShiftOut shift(11, 12, 13);

const int layerCount = 4;
PinObject layers[layerCount]
{
  PinObject(A2),
  PinObject(A3),
  PinObject(A4),
  PinObject(A5)
};

const int ledCount = 16;
PinObject leds[ledCount]
{
  PinObject(&shift, 0),
  PinObject(&shift, 1),
  PinObject(&shift, 2),
  PinObject(&shift, 3),
  PinObject(&shift, 4),
  PinObject(&shift, 5),
  PinObject(&shift, 6),
  PinObject(&shift, 7),

  PinObject(2),
  PinObject(3),
  PinObject(4),
  PinObject(5),
  PinObject(6),
  PinObject(7),
  PinObject(8),
  PinObject(9)
};

void setup()
{

}

void loop()
{

}

正如我上面所说,代码在Arduino SDK中成功验证,所以我不知道出了什么问题。确切的错误消息:

5:1: error: 'ShiftOut' does not name a type

0 个答案:

没有答案