need help with stop light project

Im new to programming, but i think i have the basics down. i jst need to make sure this would work. if u see a problem, just point it out

int R1=12
int Y1=11
int G1=10
int B1=8
int R2=5
int Y2=4
int G2=9
int B2=3

void setup ()
{
pinmode(R1, output);
pinmode(Y1, output);
pinmode(G1, output);
pinmode(B1, input);
pinmode(R2, output);
pinmode(Y2, output);
pinmode(G2, output);
pinmode(B2, input);
}

void loop()
{
if (digitalread (B1)) == HIGH;
{ G2('L');
delay(0);
Y2('H');
delay(3000);
Y2('L');
delay(0);
R2('H');
delay(1000);
G1('H');
}
if (digitalread (B2)) == HIGH;
{ G1('L');
delay(0);
Y1('H');
delay(3000);
Y1('L');
delay(0);
R1('H');
delay(1000);
G2('H');
}

OT: C/C++ is case sensitive, be sure to put ; where they are supposed to, and have fun!

I've made some adjustments, and commented in a few comments and questions :slight_smile:

#define R1 12
#define Y1 11
#define G1 10
#define B1 8 //this will override the standard definition which is 1
#define R2 5
#define Y2 4
#define G2 9
#define B2 3

#define LONG_DELAY 3000
#define SHORT_DELAY 1000

void setup ()
{
//pinmode(R1, OUTPUT); BEWARE C is case sensitive
pinMode(R1, OUTPUT);
pinMode(Y1, OUTPUT);
pinMode(G1, OUTPUT);
pinMode(B1, INPUT);
pinMode(R2, OUTPUT);
pinMode(Y2, OUTPUT);
pinMode(G2, OUTPUT);
pinMode(B2, INPUT);
}

void loop()
{
//if (digitalread (B2)) == HIGH;
if ( digitalRead(B1) == HIGH )
{
//G2('L'); what is this?
//Y2('H'); i guess:
digitalWrite(G2,LOW);
digitalWrite(Y2,HIGH);
delay(LONG_DELAY);
//Y2('L');
//R2('H');
delay(SHORT_DELAY);
//G1('H');
}
if ( digitalRead(B2) == HIGH )
{
//G1('L');
//Y1('H');
delay(LONG_DELAY);
//Y1('L');
//R1('H');
delay(SHORT_DELAY);
//G2('H');
}
}//end loop

Just for the fun of it:

//hacked to your syntax :)

//define IO
#define r1 12
#define y1 11
#define g1 10
#define b1 8 //this will override the standard definition which is 1
#define r2 5
#define y2 4
#define g2 9
#define b2 3

//macros
#define R1(x) ( x=='H' ? digitalWrite(r1,HIGH) : digitalWrite(r1,LOW) )
#define Y1(x) ( x=='H' ? digitalWrite(y1,HIGH) : digitalWrite(y1,LOW) )
#define G1(x) ( x=='H' ? digitalWrite(g1,HIGH) : digitalWrite(g1,LOW) )
#define R2(x) ( x=='H' ? digitalWrite(r2,HIGH) : digitalWrite(r2,LOW) )
#define Y2(x) ( x=='H' ? digitalWrite(y2,HIGH) : digitalWrite(y2,LOW) )
#define G2(x) ( x=='H' ? digitalWrite(g2,HIGH) : digitalWrite(g2,LOW) )


#define LONG_DELAY 3000
#define SHORT_DELAY 1000

void setup ()
{
 //pinmode(R1, OUTPUT);  BEWARE C is case sensitive
 pinMode(r1, OUTPUT);
 pinMode(y1, OUTPUT);
 pinMode(g1, OUTPUT);
 pinMode(b1, INPUT);
 pinMode(r2, OUTPUT);
 pinMode(y2, OUTPUT);
 pinMode(g2, OUTPUT);
 pinMode(b2, INPUT);
}

void loop()
{
 //if (digitalread (B2)) == HIGH;
 if ( digitalRead(b1) == HIGH )
 {
   G2('L'); 
   Y2('H'); 
   delay(LONG_DELAY);
   Y2('L');
   R2('H');
   delay(SHORT_DELAY);
   G1('H');
 }
 if ( digitalRead(b2) == HIGH )
 {  
   G1('L');
   Y1('H');
   delay(LONG_DELAY);
   Y1('L');
   R1('H');
   delay(SHORT_DELAY);
   G2('H');
 }
}//end loop

just to be sure you are writing in arduino programming right?

I am. My code compiles with arduino IDE.

You often forget case sensitivity. In arduino pinmode and pinMode are two different things. You also tend to forget the ; , as seen in your list of variables on top of your code. :slight_smile:

if syntax is also a bit off, this is correct:

if (condition ){
  //execute
}

If you are new to this, it's often recommanded to look at the example codes, and tweak them to death and beyond. :wink:

[ and.. is the KH2 in your nick by any chanse an indication of you being a guitarist? 8-)]

i did look at the reference, but i can look again.

[and i am a guitarist but no its just an abbreviation for Kingdom Hearts 2 =)]

If you wrote that code after just looking at the reference I think you'll get the hang of this very fast.

Have you downloaded the arduino IDE? Bought an arduino yet? :slight_smile:

[I thought it was the name of Kirk Hammet's signature guitar, funny coincidence]

if (digitalread (B2)) == HIGH;
{

The syntax here is a bit mixed-up. What I think you need to write is:

if (digitalRead (B2) == HIGH)
{

The entire conditional part of an 'if' must be enclosed in round brackets. Semi-colons are only needed at the end of a statement, such as:

int B2=3;

well its a project for an after school program, and the teacher has the arduino installed onto his computers, but i dont have it at home.

The syntax here is a bit mixed-up. What I think you need to write is:

Code:if (digitalRead (B2) == HIGH)
{

The entire conditional part of an 'if' must be enclosed in round brackets. Semi-colons are only needed at the end of a statement, such as:

and thanx