Shift Registers Help

I was watching a tutorial on YouTube (Arduino Tutorial #3 - Shift Registers (74HC595) - YouTube) about creating a shift register and I'm a little stuck. I am a complete beginner to electronic, but I do have a background in computers. A lot of this made sense but this one is confusing me. I complied my file and had a couple typos which I fixed, but now I am getting this error:


Arduino: 1.8.13 (Mac OS X), Board: "Arduino Uno"

/Users/Arduino/Resinator/Shift2/Shift2.ino: In function 'void writereg()':
Shift2:21:36: error: invalid types 'boolean {aka bool}[int]' for array subscript
digitalWrite(DS_pin,registers*);*

  • ^*
    /Users/Arduino/Resinator/Shift2/Shift2.ino: In function 'void loop()':
    Shift2:31:16: error: invalid types 'boolean {aka bool}[int]' for array subscript
    _ registers*=HIGH;_
    _
    ^_
    exit status 1
    invalid types 'boolean {aka bool}[int]' for array subscript
    This report would have more information with
    _
    "Show verbose output during compilation"_
    option enabled in File -> Preferences.
    _____
    Here is my code:
    _
    ```*_
    *int DS_pin = 4;
    int STCP_pin = 5;
    int SHCP_pin = 6;

void setup()
{
pinMode(DS_pin, OUTPUT);
pinMode(STCP_pin, OUTPUT);
pinMode(SHCP_pin, OUTPUT);
writereg();
}
boolean registers(8);

void writereg()
{
digitalWrite(SHCP_pin, LOW);

for (int i = 7; 1 >= 0; i--)
{
  digitalWrite(STCP_pin, LOW);
  digitalWrite(DS_pin,registers[i]);
  digitalWrite(STCP_pin, HIGH);
}
digitalWrite(SHCP_pin, HIGH);
}

void loop()
{
for (int i = 0; i < 9; i++)
{
  registers[i]=HIGH;        // <-----this is the error line
  delay(1000);
  writereg();
}

}
_
```_
________*

I researched the problem, but I don't know how to fix it. Most answers just say that the boolean value is invalid, but not how to fix the issue or even why is it out of value/invalid. Do I just need to learn more about shift registers? or Can this code be quickly fixed? any help is welcome, even a link to a good tutorial on shift registers and how they work!

Read the how to use this forum-please read sticky to see how to properly post code and some advice on how to ask an effective question. Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code.

boolean registers(8);

maybe the smily face hid the brackets (e.g. boolean registers[8];) but even so, you use "registers" as a scalar (not an array).

a boolean in C/C++ is still an 8-bit byte. you could of course have an array of booleans but you can use a byte or a uint64_t to store individual bits that can be operated on individually

#define B_DBG  (1<<0)
#define B_RUN  (1<<1)
#define B_TXT  (1<<2)
#define BRST   (1<<3)


    if (flags & B_RST)
        flags &= ~B_RST;
    else
        flags |= B_RST

post code in tag ("</>" top left)

Sorry about the smiley

groundFungus:
Read the how to use this forum-please read sticky to see how to properly post code and some advice on how to ask an effective question. Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code.

Thanks!

gcjr:

boolean registers(8);

maybe the smily face hid the brackets (e.g. boolean registers[8];) but even so, you use "registers" as a scalar (not an array).

That fixed the error thanks! I will look into doing an array, any good tutorials that you know of?

I will look into doing an array, any good tutorials that you know of?

Tutorial about arrays
That whole site was a great help to me while I was learning C, I still go back to it when I'm not sure about something.