Pages: [1]   Go Down
Author Topic: Leds (n00b projects)  (Read 410 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
God Member
*****
Karma: 1
Posts: 733
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

ROG Led:
Code:
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:
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:
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:
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:
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);
}
Logged

B0100111001000011, USA
Offline Offline
Edison Member
*
Karma: 0
Posts: 1503
I'm confused.  Wait, maybe not..
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

0
Offline Offline
Full Member
***
Karma: 1
Posts: 223
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

London, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 46
Arduino. Great. All I need now is a project.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Superb! Keep up the good work.
Logged

Pages: [1]   Go Up
Jump to: