Go Down

Topic: Leds (n00b projects) (Read 444 times) previous topic - next topic

Jeremy1998

i am 11, so i bet these are lame, but im a noob...

ROG Led:
Code: [Select]
int RledPin =  13;   // Red on pin 13
int GledPin =  12;   // Green on pin 12

void setup()   {                
 pinMode(RledPin, OUTPUT);   // Pin 13 is an output
 pinMode(GledPin, OUTPUT);   // PIn 12 is an output    
}

void loop()   {
 digitalWrite(GledPin, HIGH);   // Turn green on
 delay(1000);                   // For 1 second
 digitalWrite(RledPin, HIGH);   // Turn red on
 delay(1000);                   // For 1 second
 digitalWrite(GledPin, LOW);    // Turn green off
 delay(1000);                   // For one second
 digitalWrite(RledPin, LOW);    // Turn red off
 delay(750);                    // For 3/4 second
}


Traffic Lights:
Code: [Select]
int RledPin =  13;   // Red on pin 13
int GledPin =  12;   // Green on pin 12
int RledPin2 = 11;   // Red on pin 11
int GledPin2 = 10;   // Green on pin 10

void setup()   {                
 pinMode(RledPin, OUTPUT);   // Pin 13 is an output
 pinMode(GledPin, OUTPUT);   // Pin 12 is an output
 pinMode(RledPin2, OUTPUT);  // Pin 11 is an output
 pinMode(GledPin2, OUTPUT);  // Pin 10 is an output
}

void loop()   {
digitalWrite(RledPin, HIGH);   // Turn LED 1 red
digitalWrite(GledPin2, HIGH);  // Turn LED 2 green
 delay(1500);                  // For 1.5 seconds  
digitalWrite(RledPin2, HIGH);  // Turn LED 2 orange
delay(1000);                   // For 1 second
digitalWrite(GledPin2, LOW);   // Turn LED 2 red
digitalWrite(RledPin, LOW);    // Turn LED 1 off
digitalWrite(GledPin, HIGH);   // Turn LED 1 green
delay(1500);                   // For 1.5 seconds
digitalWrite(RledPin, HIGH);   // Turn LED 1 orange
delay(1000);                   // For 1 second  
digitalWrite(GledPin, LOW);    // Turn LED 1 red
digitalWrite(RledPin2, LOW);   // Turn LED 2 off
digitalWrite(GledPin2, HIGH);  // Turn LED 2 green
}


Scanner Test:
Code: [Select]
int RledPin1 = 13;   // Red on pin 13
int GledPin1 = 12;   // Green on pin 12
int RledPin2 = 11;   // Red on pin 11
int GledPin2 = 10;   // Green on pin 10
int RledPin3 = 9;    // Red on pin 9
int GledPin3 = 8;    // Green on pin 8

void setup()   {                
 pinMode(RledPin1, OUTPUT);   // Pin 13 is an output
 pinMode(GledPin1, OUTPUT);   // Pin 12 is an output
 pinMode(RledPin2, OUTPUT);   // Pin 11 is an output
 pinMode(GledPin2, OUTPUT);   // Pin 10 is an output
 pinMode(RledPin3, OUTPUT);   // Pin 9 is an output
 pinMode(GledPin3, OUTPUT);   // Pin 8 is an output.
}

void loop()   {
digitalWrite(GledPin1, HIGH);  
delay(500);                  
digitalWrite(GledPin1, LOW);
digitalWrite(GledPin2, HIGH);
delay(500);                
digitalWrite(GledPin2,LOW);
digitalWrite(GledPin3, HIGH);
delay(500);                
digitalWrite(GledPin3, LOW);
digitalWrite(RledPin1, HIGH);
digitalWrite(GledPin1, HIGH);
delay(500);
digitalWrite(GledPin1, LOW);
digitalWrite(RledPin1, LOW);
digitalWrite(GledPin2, HIGH);
digitalWrite(RledPin2, HIGH);
delay(500);
digitalWrite(GledPin2, LOW);
digitalWrite(RledPin2, LOW);
digitalWrite(GledPin3, HIGH);
digitalWrite(RledPin3, HIGH);
delay(500);
digitalWrite(GledPin3, LOW);
digitalWrite(RledPin3, LOW);
digitalWrite(RledPin1, HIGH);
delay(500);
digitalWrite(RledPin1, LOW);
digitalWrite(RledPin2, HIGH);
delay(500);
digitalWrite(RledPin2, LOW);
digitalWrite(RledPin3, HIGH);
delay(500);
digitalWrite(RledPin3, LOW);
}


Scanner Slow:
Code: [Select]
int RledPin1 = 13;   // Red on pin 13
int GledPin1 = 12;   // Green on pin 12
int RledPin2 = 11;   // Red on pin 11
int GledPin2 = 10;   // Green on pin 10
int RledPin3 = 9;    // Red on pin 9
int GledPin3 = 8;    // Green on pin 8

void setup()   {                
 pinMode(RledPin1, OUTPUT);   // Pin 13 is an output
 pinMode(GledPin1, OUTPUT);   // Pin 12 is an output
 pinMode(RledPin2, OUTPUT);   // Pin 11 is an output
 pinMode(GledPin2, OUTPUT);   // Pin 10 is an output
 pinMode(RledPin3, OUTPUT);   // Pin 9 is an output
 pinMode(GledPin3, OUTPUT);   // Pin 8 is an output
}

void loop()   {
digitalWrite(GledPin1, HIGH);  
delay(300);                  
digitalWrite(GledPin1, LOW);
digitalWrite(GledPin2, HIGH);
delay(300);                
digitalWrite(GledPin2,LOW);
digitalWrite(GledPin3, HIGH);
delay(300);                
digitalWrite(GledPin3, LOW);
digitalWrite(RledPin1, HIGH);
digitalWrite(GledPin1, HIGH);
delay(300);
digitalWrite(GledPin1, LOW);
digitalWrite(RledPin1, LOW);
digitalWrite(GledPin2, HIGH);
digitalWrite(RledPin2, HIGH);
delay(300);
digitalWrite(GledPin2, LOW);
digitalWrite(RledPin2, LOW);
digitalWrite(GledPin3, HIGH);
digitalWrite(RledPin3, HIGH);
delay(300);
digitalWrite(GledPin3, LOW);
digitalWrite(RledPin3, LOW);
digitalWrite(RledPin1, HIGH);
delay(300);
digitalWrite(RledPin1, LOW);
digitalWrite(RledPin2, HIGH);
delay(300);
digitalWrite(RledPin2, LOW);
digitalWrite(RledPin3, HIGH);
delay(300);
digitalWrite(RledPin3, LOW);
}


Scanner Fast:
Code: [Select]
int RledPin1 = 13;   // Red on pin 13
int GledPin1 = 12;   // Green on pin 12
int RledPin2 = 11;   // Red on pin 11
int GledPin2 = 10;   // Green on pin 10
int RledPin3 = 9;    // Red on pin 9
int GledPin3 = 8;    // Green on pin 8

void setup()   {                
 pinMode(RledPin1, OUTPUT);   // Pin 13 is an output
 pinMode(GledPin1, OUTPUT);   // Pin 12 is an output
 pinMode(RledPin2, OUTPUT);   // Pin 11 is an output
 pinMode(GledPin2, OUTPUT);   // Pin 10 is an output
 pinMode(RledPin3, OUTPUT);   // Pin 9 is an output
 pinMode(GledPin3, OUTPUT);   // Pin 8 is an output
}

void loop()   {
digitalWrite(GledPin1, HIGH);  
delay(100);                  
digitalWrite(GledPin1, LOW);
digitalWrite(GledPin2, HIGH);
delay(100);                
digitalWrite(GledPin2,LOW);
digitalWrite(GledPin3, HIGH);
delay(100);                
digitalWrite(GledPin3, LOW);
digitalWrite(RledPin1, HIGH);
digitalWrite(GledPin1, HIGH);
delay(100);
digitalWrite(GledPin1, LOW);
digitalWrite(RledPin1, LOW);
digitalWrite(GledPin2, HIGH);
digitalWrite(RledPin2, HIGH);
delay(100);
digitalWrite(GledPin2, LOW);
digitalWrite(RledPin2, LOW);
digitalWrite(GledPin3, HIGH);
digitalWrite(RledPin3, HIGH);
delay(100);
digitalWrite(GledPin3, LOW);
digitalWrite(RledPin3, LOW);
digitalWrite(RledPin1, HIGH);
delay(100);
digitalWrite(RledPin1, LOW);
digitalWrite(RledPin2, HIGH);
delay(100);
digitalWrite(RledPin2, LOW);
digitalWrite(RledPin3, HIGH);
delay(100);
digitalWrite(RledPin3, LOW);
}

TchnclFl

Not so bad a for a "noob"!

Maybe look into learning how to effectively use "for" loops.  They can really help to shorten and clean up the code!

zitron

Dude I wish I could program arduino when I was 11...

FlyWareSoft

Nice job! Once you've got anything new like this to work, it's good to have a go at achieving the same result in a better way - like trying to find some different code to flash the lights in the same way.

Exciting, isn't it? I've been playing around with electronics for years (on and off) and I still get that tingly 'yeah' feeling when something works.

Paul.

mkalenius

Superb! Keep up the good work.

Go Up