Code help - 4 way Traffic lights and functions!

Hey guys, so i'm making a program for uni which simulates two 4-way traffic lights and a pedestrian light.
So I managed to finish the program using 'switch' statements inside functions. However I have been told by a lecturer that this is not acceptable. I can't have the Switch statements in it.
e.g.

int colour;
void trafficLight1()
{
  switch (colour) {
    case 'Red' : //Red
      digitalWrite(red, HIGH);
      digitalWrite(amber, LOW);
      digitalWrite(green, LOW);
      Serial.println("L1 = ON OFF OFF");
      break;
    case 'Amber' : //amber
      digitalWrite(red, LOW);
      digitalWrite(amber, HIGH);
      digitalWrite(green, LOW);
      Serial.println("L1 = OFF ON OFF");
      break;
    case 'Green' : //Green
      digitalWrite(red, LOW);
      digitalWrite(amber, LOW);
      digitalWrite(green, HIGH);
      Serial.println("L1 = OFF OFF ON");
      break;
    case 'RA' : //Red/Amber
      digitalWrite(red, HIGH);
      digitalWrite(amber, HIGH);
      digitalWrite(green, LOW);
      Serial.println("L1 = ON ON OFF");
      break;
  }
}

They want the code in functions like this...

void trafficLight1(int red, int amber, int green)
{
}

I've been messing around with this way and I am totally stoked at what I have to do, haha. He said it would be easy but I just keep getting this error...

"traffic_lights.ino: In function 'void trafficLight1(int, int, int)':
traffic_lights:25: error: void value not ignored as it ought to be
traffic_lights:26: error: void value not ignored as it ought to be
traffic_lights:27: error: void value not ignored as it ought to be
traffic_lights.ino: In function 'void trafficLight2(int, int, int)':
traffic_lights:31: error: 'red2On' was not declared in this scope
traffic_lights:32: error: 'amberOn' was not declared in this scope
traffic_lights:33: error: 'greenOn' was not declared in this scope
traffic_lights.ino: In function 'void loop()':
traffic_lights:37: error: too few arguments to function 'void trafficLight1(int, int, int)'
traffic_lights.ino:23:6: note: declared here
traffic_lights:38: error: too few arguments to function 'void trafficLight2(int, int, int)'
traffic_lights.ino:29:6: note: declared here
traffic_lights:41: error: too few arguments to function 'void trafficLight1(int, int, int)'
traffic_lights.ino:23:6: note: declared here
traffic_lights:42: error: too few arguments to function 'void trafficLight2(int, int, int)'
traffic_lights.ino:29:6: note: declared here
traffic_lights:45: error: too few arguments to function 'void trafficLight1(int, int, int)'
traffic_lights.ino:23:6: note: declared here
traffic_lights:46: error: too few arguments to function 'void trafficLight2(int, int, int)'
traffic_lights.ino:29:6: note: declared here
traffic_lights:49: error: too few arguments to function 'void trafficLight1(int, int, int)'
traffic_lights.ino:23:6: note: declared here
traffic_lights:50: error: too few arguments to function 'void trafficLight2(int, int, int)'
traffic_lights.ino:29:6: note: declared here
traffic_lights:58: error: too few arguments to function 'void trafficLight1(int, int, int)'
traffic_lights.ino:23:6: note: declared here
traffic_lights:59: error: too few arguments to function 'void trafficLight2(int, int, int)'
traffic_lights.ino:29:6: note: declared here
traffic_lights:68: error: too few arguments to function 'void trafficLight2(int, int, int)'
traffic_lights.ino:29:6: note: declared here
void value not ignored as it ought to be"

Below is the whole code that I am currently trying...

const int red = 13; // the pin that the LED is attached to
const int amber = 12;
const int green = 11;
const int red2 = 10;
const int amber2 = 9;
const int green2 = 8;
const int pedGreen = 7;
int incomingByte;      // a variable to read incoming serial data into

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
  // initialize the LED pin as an output:
  pinMode(red, OUTPUT);
  pinMode(amber, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(red2, OUTPUT);
  pinMode(amber2, OUTPUT);
  pinMode(green2, OUTPUT);
  pinMode(pedGreen, OUTPUT);
}

void trafficLight1(int red, int amber, int green)
{
  red = digitalWrite(red, HIGH);
  amber = digitalWrite(amber, HIGH);
  green = digitalWrite(green, HIGH);
}
void trafficLight2(int red2, int amber2, int green2)
{
  red2 = digitalWrite(red2, HIGH);
  amber2 = digitalWrite(amber2, HIGH);
  green2 = digitalWrite(green2, HIGH);
}
void loop()
{
  trafficLight1(red);
  trafficLight2(green);
  Serial.print("L1 = ON OFF OFF   L2 = OFF OFF ON   PED = OFF");
  delay(2000);
  trafficLight1(red, amber);
  trafficLight2(amber2);
  Serial.print("L1 = ON ON OFF   L2 = OFF ON OFF    PED = OFF");
  delay(2000);
  trafficLight1(green);
  trafficLight2(red2);
  Serial.print("L1 = OFF OFF ON  L2 = ON OFF OFF    PED = OFF");
  delay(2000);
  trafficLight1(amber);
  trafficLight2(red2, amber2);
  Serial.print("L1 = OFF ON OFF   L2 = ON ON OFF    PED = OFF");
  delay(2000);

  if (Serial.available() > 0)   // see if there's incoming serial data
  {
    incomingByte = Serial.read();   // read the oldest byte in the serial buffer
    digitalWrite(pedGreen, HIGH);
    trafficLight1(red);
    trafficLight2(red2);
    delay(5000);
    for (int x = 0; x < 10; x++)
    {
      digitalWrite(pedGreen, HIGH);
      delay(150);
      digitalWrite(pedGreen, LOW);
      delay(150);
    }
    trafficLight2(red2, amber2);
    delay(2000);
  }
}

Any help with this would be greatly appreciated, it's due Monday but uni doesn't open again until late August so can't ask a lecturer for help.

~ Jake

p.s. Sorry if this is a bit too long for a topic, the code takes up a lot of space, aha.
p.p.s. Attached is a picture of the requirements, if you fancy checking out what I have to do to get a better understanding of my issue. Thanks

omgzzz:
Hey guys, so i'm making a program for uni which simulates two 4-way traffic lights and a pedestrian light.

When I read your tasks in the picture you posted, I read that you have to do THREE flowcharts and THREE C-programs.

1.) Single 4-phase traffic light
2.) Two 4-phase traffic lights at a crossroad junction
3.) Same like 2., but with an additional pedestrian light and a button for pedestrian green request

You have 1.) and 2.) already done?

Yeah,

I made one traffic light and documented it, then I made another light in the same program and documented it.
Now I have made the pedestrian light as well, but I have used the wrong method on them.

I just need some help with figuring out how to do the "trafficLight1(int red,int amber,int green){}" part instead of using the switch statement.

~ Jake

omgzzz:
I just need some help with figuring out how to do the "trafficLight1(int red,int amber,int green){}" part instead of using the switch statement.

I don't know what's expected from you.

But I know, that you cannot use the same variable names for different things in your program at the same time. I think you already use red, amber, green as digital pin numbers. Now you cannot use the same names within a function for something completely different. I'd avoid to name each and every variable 'red'. You are allowed to use longer variable names, so that the variable name tells you whether it is the a pin or as on/off-state!

Perhaps you can use something like that (in the code I used red1pin, amber1pin and green1pin as pin numbers):

void printLightState(boolean on)
{
  if (on) Serial.print("ON ");
  else Serial.print("OFF ");
}

void trafficLight1(boolean redOn, boolean amberOn, boolean greenOn)
{
  Serial.print("L1= ");
  digitalWrite(red1pin, redOn);
  printLightState(redOn);
  digitalWrite(amber1pin, amberOn);
  printLightState(amberOn);
  digitalWrite(green1pin, greenOn);
  printLightState(greenOn);
  Serial.println();
}

Instead of integers I used booleans for the state of the lamps.

So if you want to set "red ON, amber OFF, green OFF", you call the function with code:

trafficLight1(true,false,false);

You have to understand: You cannot use 'red' as a pin number and 'red' as the pin state at the same time. So use different names. Use "speaking names", then your code is self-commenting.

Like shown I'd use for the pin numbers: red1pin, amber1pin, green1pin
And for the pin states a 'boolean': redOn, amberOn, greenOn (which is then 'true' or 'false')

jurs, thank you so much!

I used the (true, false, false);
but int redOn instead of boolean redOn.

Here's some of the code that I have changed.

void trafficLight1(int redOn, int amberOn, int greenOn)
{
  digitalWrite(red, redOn);
  digitalWrite(amber, amberOn);
  digitalWrite(green, greenOn);
}
void loop()
{
  trafficLight1(true,false,false);
  trafficLight2(false,false,true);
  Serial.println("L1 = ON OFF OFF   L2 = OFF OFF ON   PED = OFF");
  delay(2000);

It seems to be working now and it ticks all of the criteria so I'm going to upload the assignment and move onto the next, aha.

Again cheers for the help. I thought I was going to have to upload the working 'Switch' statement version and possibly fail.

Many thanks

~ Jake

Wonderful,
before you had variable "color", now you passed variables are "true / false".
Ask you teacher about writing "self documenting code".

C minus in my grading book.