c++arduinoshift-register

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


Warning: I'm new to C++ (and most of programming in general) and am learning the language to be able to write code for my arduino

I'm learning how to use a shift register using the Arduino IDE which i believe is in C++.

Here is the code:

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
  }
}

and here is the error which I do not understand what it means and what I should do about it


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

Solution

  • This line is the problem:

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

    Change it to:

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