hey everyone, I've been working on this code and have almost got it done and squared away. Just have 1 issue that seems to be holding me up. I'm basically using a binary input to control multiple outputs. I'm trying to add a password, only 4 digits, to the beginning of the code and i think i have that bit squared away. I moved my switching commands themselves to a subroutine and I believe that is correct but I am having issues compiling it. Every time I attempt to compile I receive this error...
"error: a function-definition is not allowed here before '{' token"
any help anyone can give me would be beyond appreciated.
int inPin1 = 0; //Input from DTMF Decoder
int inPin2 = 1; //Input from DTMF Decoder
int inPin3 = 2; //Input from DTMF Decoder
int inPin4 = 3; //Input from DTMF Decoder
int outPin1 = 45; //output for Device 1
int outPin2 = 44; //Output for Device 2
int outPin3 = 43; //Output for Device 3
int outPin4 = 42; //Output for Device 4
int lockPin1 = 23; //Lock Pin for Device 1
int lockPin2 = 22; //Lock Pin for Device 2
int lockPin3 = 21; //Lock Pin for Device 3
int lockPin4 = 20; //Lock Pin for Device 4
int engagePin = 40;
void setup ()
{ //Set Input assignments for Pins
pinMode (inPin1, INPUT); //Most Signifacant Bit
pinMode (inPin2, INPUT); //
pinMode (inPin3, INPUT); //
pinMode (inPin4, INPUT); //Most Significant Bit
//Set Output assignments for Pins
pinMode (outPin1, OUTPUT); //Device number 1
pinMode (outPin2, OUTPUT); //Device number 2
pinMode (outPin3, OUTPUT);
pinMode (outPin4, OUTPUT);
pinMode (lockPin1, OUTPUT); //lockPin1 for Device 1
pinMode (lockPin2, OUTPUT); //lockPin2 for Device 2
pinMode (lockPin3, OUTPUT);
pinMode (lockPin4, OUTPUT);
pinMode (engagePin, OUTPUT);
void doSwitching (void) //Switching subroutine
{
//Switching commands for devices on pins 45 & 42
//Start switching Commands
if (inPin1 == LOW && inPin2 == LOW && inPin3 == LOW && inPin4 == HIGH || lockPin1 == HIGH) //Binary 1
{
digitalWrite (outPin1, HIGH) && digitalWrite (lockPin1, HIGH); //Set lockPin1 and outPin1 HIGH
}
else if (inPin1 == LOW && inPin2 == LOW && inPin3 == HIGH && inPin4 == LOW) //Binary 2
{
digitalWrite (outPin1, LOW) && digitalWrite (lockPin1, LOW); //Reset lockPin1 and outPin1 LOW
}
else if (inPin1 == LOW && inPin2 == LOW && inPin3 == HIGH && inPin4 == HIGH || lockPin2 == HIGH) //Binary 3
{
digitalWrite (outPin2, HIGH) && digitalWrite (lockPin2, HIGH); //Set lockPin2 and outPin2 HIGH
}
else if (inPin1 == LOW && inPin2 == HIGH && inPin3 == LOW && inPin4 == LOW) //Binary 4
{
digitalWrite (outPin2, LOW) && digitalWrite (lockPin2, LOW); //Reset lockPin2 and outPin2 LOW
}
else if (inPin1 == LOW && inPin2 == HIGH && inPin3 == LOW && inPin4 == HIGH || lockPin3 == HIGH) //Binary 5
{
digitalWrite (outPin3, HIGH) && digitalWrite (lockPin3, HIGH); //Set lockPin3 and outPin3 HIGH
}
else if (inPin1 == LOW && inPin2 == HIGH && inPin3 == HIGH && inPin4 == LOW) //Binary 6
{
digitalWrite (outPin3, LOW) && digitalWrite (lockPin3, LOW); //Set lockPin3 and outPin3 LOW
}
else if (inPin1 == LOW && inPin2 == HIGH && inPin3 == HIGH && inPin4 == HIGH || lockPin4 == HIGH) //Binary 7
{
digitalWrite (outPin4, HIGH) && digitalWrite (lockPin4, HIGH); //Set lockPin4 and outPin4 HIGH
}
else if (inPin1 == HIGH && inPin2 == LOW && inPin3 == LOW && inPin4 == LOW) //Binary 8
{
digitalWrite (outPin4, LOW) && digitalWrite (lockPin4, LOW); //Set lockPin4 and outPin4
}
else if (inPin1 == HIGH && inPin2 == LOW && inPin3 == LOW && inPin4 == HIGH) //Binary 9
{ //When a Binary 9 registers shut off ALL attached devices
digitalWrite (outPin1, LOW) && digitalWrite (lockPin1, LOW) && digitalWrite (outPin2, LOW) && digitalWrite (lockPin2, LOW);
digitalWrite (outPin3, LOW) && digitalWrite (lockPin3, LOW) && digitalWrite (outPin4, LOW) && digitalWrite (lockPin4, LOW);
}
else if (inPin1 == HIGH && inPin2 == LOW && inPin3 == HIGH && inPin4 == LOW) //Binary 10, keypad 0
{
//Do nothing
}
else if (inPin1 == HIGH && inPin2 == LOW && inPin3 == HIGH && inPin4 == HIGH) //Binary 11, keypad *
{
//Do nothing
}
else if (inPin1 == HIGH && inPin2 == HIGH && inPin3 == LOW && inPin4 == LOW) //Binary 12, keypad #
{
//Do nothing
}
else //Default for when device is first activated. Sets all attached devices in Off mode.
{
digitalWrite (outPin1, LOW) && digitalWrite (outPin2, LOW) && digitalWrite (outPin3, LOW) && digitalWrite (outPin4, LOW);
digitalWrite (lockPin1, LOW) && digitalWrite (lockPin2, LOW) && digitalWrite (lockPin3, LOW) && digitalWrite (lockPin4, LOW);
}
}
void loop () //Main Passwrod Loop
{
//Binary input from 8870 Chip
inPin1 = digitalRead(0) && inPin2 = digitalRead(1) && inPin3 = digitalRead(2) && inPin4 = digitalRead(3);
//read statements for state lock on outputs
lockPin1 = digitalRead(23) && lockPin2 = digitalRead(22) && lockPin3 = digitalRead(21) && lockPin4 = digitalRead(20);
enagePin = digitalRead(40);
//Password setting
if (inPin1 == LOW && inPin2 == LOW && inPin3 == LOW && inPin4 == HIGH) //Binary 1
{
if (inPin1 == LOW && inPin2 == LOW && inPin3 == LOW && inPin4 == HIGH) //Binary 1
{
if (inPin1 == LOW && inPin2 == LOW && inPin3 == LOW && inPin4 == HIGH) //Binary 1
{
if (inPin1 == LOW && inPin2 == LOW && inPin3 == LOW && inPin4 == HIGH) //Binary 1
{
digitalWrite (engagePin, HIGH);
digitalWrite (outPin1, LOW) && digitalWrite (lockPin1, LOW) && digitalWrite (outPin2, LOW) && digitalWrite (lockPin2, LOW);
digitalWrite (outPin3, LOW) && digitalWrite (lockPin3, LOW) && digitalWrite (outPin4, LOW) && digitalWrite (lockPin4, LOW);
doSomething ();
}
else
{
digitalWrite (engagePin, LOW);
}
}
else
{
digitalWrite (engagePin, LOW);
}
}
else
{
digitalWrite (engagePin, LOW);
}
}
else
{
digitalWrite (engagePin, LOW);
}
}