Project Help!

Imgur

I have linked the circuit diagram that I am using. I have four 74HC165N chips, an Arduino Uno and a VoiceBox Shield. Each of the green inputs on the 74HC165N chips will have a wire attached so I left those out of the diagram for simplicity.

What I am trying to do is connect each wire to different circuits (labeled 1-28). Then when I take the test probe and touch different parts of the circuit, I want the Arduino to say the circuit number that has been completed.

I have written some code and it is pasted at the end of this comment. I wrote the setup code correctly but I really have no idea what to do with the “loop” part. I really took a wild guess and I assume that it is wrong.

If anyone can please give me some pointers on my circuit, the code I have and what additional code I should have, that would be greatly appreciated.

This is my first Arduino project and I feel completely lost at this point so please help!

#include Wire
#include SoftwareSerial

long pload_Pin = 8;
long clockenable_Pin = 9;
long data_Pin = 11;
long clock_Pin = 12;

#define number_of_registers 4   //This amount can change
#define number_of_register_pins number_of_registers *8  //This amount can change
#define bytes_value unsigned int

boolean registers[number_of_register_pins];

int val = 0;
int stp = 0;

void setup() 
{
  Serial.begin(9600); //transfer rate
  
  //setting up the four pins to be compliant with the parallel switches
  pinMode(pload_Pin, INPUT);
  pinMode(clockenable_Pin, INPUT);
  pinMode(clock_Pin, INPUT);
  pinMode(data_Pin, OUTPUT);
  
  //Resets all register pins
  clearRegisters();
  writeRegisters();
  
  //set all register pins to LOW
void clearRegisters()
{
 for(int i = number_of_register_pins - 1; i >= 0; i--)
 {
  registers[i] = LOW;
 }  
}

void writeRegisters()
{
 digitalWrite(clockenable_Pin, LOW);
 for(int i = number_of_register_pins -1; i >= 0; i--)
{
 digitalWrite(clock_Pin, LOW);
 int val = registers[i];
 digitalWrite(pload_Pin, val)'
 digitalWrite(data_Pin, HIGH);
}
 digitalWrite(clockenable_Pin, HIGH);
}

//set an individual pin HIGH or LOW
void setRegisterPin(int index, int value)
{
 registers[index] = value;
}
  
void loop() 
{
 for (stp; stp >= number_of_register_pins; stp++)
 {
  val = digitalRead(stp)
  
  if (val=1)
  {
   //Output Audio File 1
   delay(2000);  //2 second delay
   digitalWrite(1, LOW);
   }
   if (stp == number_of_regieter_pins; stp+++)
   {
    stp=0;
   }   
  }
  //  Repeat for 0-26
}
#include Wire
#include SoftwareSerial

What do you think these are doing? I doubt that they are doing that.

You need to understand what the { and } are for. They define blocks of code. Some of those blocks can have other blocks inside of them, and some can not.

The block that is started with a type and a function name can not be embedded in another block of the same type (another function) as you are trying to do with all of your functions (placing them inside setup).

The Tools + Auto Format menu item is your friend. Use it often.

I have updated my code a little bit:

long pload_Pin = 8;
long clockenable_Pin = 9;
long data_Pin = 11;
long clock_Pin = 12;

#define number_of_registers 4   //This amount can change
#define number_of_register_pins number_of_registers *8  //This amount can change
#define bytes_value unsigned int

boolean registers[number_of_register_pins];

int val = 0;
int stp = 0;

void clearRegisters()
{
 for(int i = number_of_register_pins - 1; i >= 0; i--)
 {
  registers[i] = LOW;
 }  
}

void writeRegisters()
{
 digitalWrite(clockenable_Pin, LOW);
 for(int i = number_of_register_pins -1; i >= 0; i--)
{
 digitalWrite(clock_Pin, LOW);
 int val = registers[i];
 digitalWrite(pload_Pin, val);
 digitalWrite(data_Pin, HIGH);
}
 digitalWrite(clockenable_Pin, HIGH);
}


//set an individual pin HIGH or LOW
void setRegisterPin(int index, int value)
{
 registers[index] = value;
}


void setup() 
{
  Serial.begin(9600); //transfer rate
  
  //setting up the four pins to be compliant with the parallel switches
  pinMode(pload_Pin, INPUT);
  pinMode(clockenable_Pin, INPUT);
  pinMode(clock_Pin, INPUT);
  pinMode(data_Pin, OUTPUT);
  
  //Resets all register pins
  clearRegisters();
  writeRegisters();
  
  //set all register pins to LOW
}


  
void loop()
{
 for (stp; stp >= number_of_register_pins; stp++)
 {
  val = digitalRead(stp);
  
  if (val=1)
  {
   //Output Audio File 1
   delay(2000);  //2 second delay
   digitalWrite(1, LOW);
   }
   if(stp == number_of_register_pins)
   {
    stp=0;
   }   
  }
  //  Repeat for 0-26
}
void writeRegisters()
{
 digitalWrite(clockenable_Pin, LOW);
 for(int i = number_of_register_pins -1; i >= 0; i--)
{
 digitalWrite(clock_Pin, LOW);
 int val = registers[i];
 digitalWrite(pload_Pin, val);
 digitalWrite(data_Pin, HIGH);
}
 digitalWrite(clockenable_Pin, HIGH);
}

This is NOT the way Tools + Auto format would format your code. Why are you not using it?

void setRegisterPin(int index, int value)
{
 registers[index] = value;
}

Registers is an array of booleans. Why are you trying to store ints in this array?

 for (stp; stp >= number_of_register_pins; stp++)

Why is stp not given an initial value?

  if (val=1)

Ah, yes. The classic wrong operator. You want ==, not =.

   if(stp == number_of_register_pins)
   {
    stp=0;
   }

Apparently, you need to study for loops some more.

And, finally, posting code without telling us what problems you are having makes it difficult to focus on your problem.

-I used the Auto-Format function before I posted the second round of code. So i don't know if something just didn't copy over correctly.
-stp was given an initial value of 0
-fixed the = to ==
-Why? What the last for loop was suppose to do was cycle through each register pin, detect if there was a change, then output the audio file (haven't figured out how to do this). Then once sep got to the last pin, it would reset to 0 (an infinite loop basically)

Right now everything compiles correctly but I know the code is not done. I posted this because I have no idea where to go now. How to go on completing the task.

The arduino will perform continuity tests and only one circuit may be completed at a time. Once the circuit is completed, the arduino should output the audio file number of the circuit