0

警告:我是 C++ 新手(以及大多数编程方面的新手),并且正在学习能够为我的 arduino 编写代码的语言

我正在学习如何使用我相信在 C++ 中的 Arduino IDE 使用移位寄存器。

这是代码:

const int latchPin = 12; // connected to ST_CP of 74HC595
const int clockPin = 8; // connected to SH_CP of 74HC595
const int dataPin = 11; // connected to DS of 74HC595
// display 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, b, C, d, E, F
int datArray[16] = (252, 96, 218, 242, 102, 182, 190, 224, 254, 246, 238, 62, 156, 122, 158, 142);

void setup()
{
  //set pins to output
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
}

void loop()
{
  //loop from 0 to 256
  for(int num = 0; num < 16; num++)
  {
    digitalWrite(latchPin, LOW); //ground latchPin and hold low for as long as you are transmitting
    shiftOut(dataPin, clockPin, MSBFIRST, datArray[num]); //MSBFIRST means most significant bit first
    // return the latch pin high to signal chip that it no longer needs to listen for information
    digitalWrite=(latchPin, HIGH); // pull the latchpin to save the data
    delay(1000); // wait for a second
  }
}

这是错误,我不明白它的含义以及我应该怎么做


shift_register:5:92: error: array must be initialized with a brace-enclosed initializer

 int datArray[16] = (252, 96, 218, 242, 102, 182, 190, 224, 254, 246, 238, 62, 156, 122, 158, 142);

                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~

C:\Users\HP\Desktop\VSc Code\Arduino\shift_register\shift_register.ino: In function 'void loop()':

shift_register:22:33: error: assignment of function 'void digitalWrite(uint8_t, uint8_t)'

     digitalWrite=(latchPin, HIGH); // pull the latchpin to save the data

                                 ^

shift_register:22:33: error: cannot convert 'int' to 'void(uint8_t, uint8_t) {aka void(unsigned char, unsigned char)}' in assignment

exit status 1
array must be initialized with a brace-enclosed initializer
4

1 回答 1

1

这条线是问题所在:

 int datArray[16] = (252, 96, 218, 242, 102, 182, 190, 224, 254, 246, 238, 62, 156, 122, 158, 142);

将其更改为:

 int datArray[16] = {252, 96, 218, 242, 102, 182, 190, 224, 254, 246, 238, 62, 156, 122, 158, 142};
于 2020-06-06T21:31:38.637 回答