Stair Led Tracking System Code Problem

Hi. First of all, I wrote this through translation, so there may be some typos. There is a stair step tracking led system. I've done this before and it worked. But now when I do it again as a project, I get the following error. I don't know how to write code. Would you help me with this topic?

Code Here

int led = 13;
int sensorUp = 7;
int sensorDown = 6;
int latchPin = 9 ; //Pin conectado a ST_CP of 74HC595 (Amarillo)
int clockPin = 10; //Pin conectado a SH_CP of 74HC595 (Amarillo)
boolean registers[17];
int dataPin = 8; //Pin connected to DS of 74HC595 (Amarillo)

// the setup routine runs once when you press reset:
 pinMode(latchPin, OUTPUT);
void setup() {
 // initialize the digital pin as an output.
 pinMode(sensorUp, INPUT);
 pinMode(sensorDown, INPUT);
 for (int i = 16; i>=0; i--)
 pinMode(clockPin, OUTPUT);
 pinMode(dataPin, OUTPUT);
 writereg();
}

void writereg()
{
 digitalWrite(latchPin, LOW) ;
 {
// the loop routine runs over and over again forever:
 digitalWrite(clockPin, LOW);
 digitalWrite(dataPin, registers[i] );
 digitalWrite(clockPin, HIGH);
 }
 digitalWrite(latchPin, HIGH);
}


void loop() {
 for(int i = 0; i<17; i++) { registers[i] = LOW; delay(200); writereg(); }
 if (digitalRead(sensorUp) == HIGH){
 for(int i = 0; i<17; i++) { registers[i] = HIGH; delay(200); writereg(); }
 delay(500);
 }
 if (digitalRead(sensorDown) == HIGH){ 
}
 for(int i = 16; i>=0; i--) { registers[i] = HIGH; delay(200); writereg(); }
 delay(500);
 for(int i = 16; i>=0; i--) { registers[i] = LOW; delay(200); writereg(); }
 } 

This is warning?

10:9: error: expected constructor, destructor, or type conversion before '(' token
 In function 'void writereg()':
27:34: error: 'i' was not declared in this scope
 exit status 1

That pinMode should be inside setup ()

As for the other one, it's hard to tell what you're trying to do.

You seem to have a loop-related comment in the writeReg function.
That seems odd.

registers is a Boolean array - you should not be assigning the values HIGH or LOW to its elements.

Thank you very much for your quick reply. I made the first edit. Can you check the project for the other one?

I don't do TinkerCAD - you need to post your code.

Hello mtnaygn

try this

void writereg()
{
 digitalWrite(latchPin, LOW) ;
}

Have a nice day and enjoy coding in C++.

Sorry. I don't understand where to try this? If possible can you share the whole code?

Here is the circuit diagram

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.