Hi peeps, my coding skills are rather limited & I need a few pointers. I'm reading 4 digital inputs and, depending on their value, setting 8 digital outputs. As I need to drive 8 outputs from just 4 inputs I'm using some simple binary to handle it. For example:
If input: pin 1=LOW, pin 2=LOW, pin 3=LOW, pin 4=HIGH then that's a binary 1 so set digital output pin 1 to HIGH
And so forth...
Here's my code so far, I'm struggling!
int outPins[] = {2,3,4,5,6,7,8,9}; // array of the output pins connected to the driver board
int inPins[] = {10,11,12,13}; // array of the input pins
int val = 0; // variable for reading the pin status
int inputstatus[] = {10,11,12,13}; // array of the input pin status
int num_outpins = 6; // the number of output pins (i.e. the length of the array)
int num_inpins = 4; // the number of input pins (i.e. the length of the array)
void setup()
{
int i;
for (i = 0; i < num_outpins; i++) // the array elements are numbered from 0 to num_outpins - 1
pinMode(outPins*, OUTPUT); // set each pin as an output*
}
{
- int g;*
- for (g = 0; g < num_inpins; g++) // the array elements are numbered from 0 to num_inpins - 1*
_ pinMode(inPins*, INPUT); // set each pin as an input*_
}
void loop(){
* //check input pins*
* int f;*
* for (f = 0; g < num_inpins; f++) // the array elements are numbered from 0 to num_inpins - 1*
* inputstatus[f] = digitalRead([f]); // read input values*
* // now set the pins that only have a single value*
* if (inPins(4) == HIGH) { // check if the input is HIGH - that means the corrsponding relay should be turned on*
* digitalWrite(outPins(2), HIGH); // turn output pin 2 On*
* }*
* if (inPins(3) == HIGH) { // check if the input is HIGH - that means the corrsponding relay should be turned on*
* digitalWrite(outPins(3), HIGH); // turn output pin 3 On*
* }*
* if (inPins(2) == HIGH) { // check if the input is HIGH - that means the corrsponding relay should be turned on*
* digitalWrite(outPins(3), HIGH); // turn output pin 3 On*
* }*
* if (inPins(1) == HIGH) { // check if the input is HIGH - that means the corrsponding relay should be turned on*
* digitalWrite(outPins(8), HIGH); // turn output pin 8 On*
* }*
}
}