Go Down

Topic: My First two programs! (Read 297 times) previous topic - next topic

ghostkeeper

Hello all,

This is my first post, I am loving the Arduino!

I Just wrote my first two programs based on the Blink example. I know they probably already exist in about a thousand different iterations but I'm as excited as Tom Cruise with a new pair of platform shoes  :)

Code: [Select]
/*
  LED_Sequence
  Turns on LEDs in a linear sequence
  Based on Blink by Scott Fitzgerald

  This code is in the public domain

  Modified Dec 1 2015
 */

//Inputs we will be using
const int LED1 = 12;
const int LED2 = 10;
const int LED3 = 8;
const int LED4 = 6;

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pins 12, 10, 8, 6 as outputs.
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(LED4, OUTPUT);
}

// the loop function runs over and over again
// until Keith Richards sheds his mortal coil
void loop() {
  digitalWrite(LED1, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(150);                 // keep on for specified time | delay(n)
  digitalWrite(LED1, LOW);    // turn the LED off by making the voltage LOW
  digitalWrite(LED2, HIGH);   // and so on
  delay(150);                 // and so on
  digitalWrite(LED2, LOW);    // and so on
  digitalWrite(LED3, HIGH);   // and so on
  delay(150);                 // and so on
  digitalWrite(LED3, LOW);    // and so on
  digitalWrite(LED4, HIGH);   // and so on
  delay(150);                 // and so on
  digitalWrite(LED4, LOW);    // and so on

}


Code: [Select]
/*
  LED_Sequence2
  Turns on LEDs in a back and forth sequence
  Based on Blink by Scott Fitzgerald

  This code is in the public domain

  Modified Dec 1 2015
 */

//Inputs we will be using
const int LED1 = 12;
const int LED2 = 10;
const int LED3 = 8;
const int LED4 = 6;

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pins 12, 10, 8, 6 as outputs.
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(LED4, OUTPUT);
}

// the loop function runs over and over again
// until Keith Richards sheds his mortal coil
void loop() {
  digitalWrite(LED1, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(150);                 // keep on for specified time | delay(n)
  digitalWrite(LED1, LOW);    // turn the LED off by making the voltage LOW
  digitalWrite(LED2, HIGH);   // and so on
  delay(150);                 // and so on
  digitalWrite(LED2, LOW);    // and so on
  digitalWrite(LED3, HIGH);   // and so on
  delay(150);                 // and so on
  digitalWrite(LED3, LOW);    // and so on
  digitalWrite(LED4, HIGH);   // and so on
  delay(150);                 // and so on
  digitalWrite(LED4, LOW);    // and so on
  digitalWrite(LED3, HIGH);   // and now back the other way
  delay(150);                 // and so on
  digitalWrite(LED3, LOW);    // and so on
  digitalWrite(LED2, HIGH);   // and so on
  delay(150);                 // and so on
  digitalWrite(LED2, LOW);    // and so on


}

dmjlambert

That is excellent!   Welcome to the forum.

weedpharma

Continue your learning experience by getting rid of the delays by using millis().

Weedpharma

ghostkeeper

Thanks all for the encouragement. :D

I'm doing the Make: Getting Started with Arduino but I'm going to comb through he commands here and play some more

Go Up