3Pi Projects‎ > ‎

Project 2 - Blink the LEDs

/* ############################################################################ 
   ##                                                                        ## 
   ##                    Project 2                                           ##
   ##                    Blink the LEDs                                      ##
   ##                    https://sites.google.com/site/3piprojects/          ##
   ##                                                                        ##
   ##                    Daniel J. Sullivan                                  ##
   ##                    Last Updated 08/08/2011                             ##
   ##                                                                        ##
   ############################################################################
   

    1. Use the same initial code as in Project 1.
    2. Assign pinModes for the on board red and green LEDs.
    3. Place a blink routine in the main loop section of the program.
*/

#include <OrangutanAnalog.h>
#include <OrangutanLCD.h>

int bat = OrangutanAnalog::readBatteryMillivolts();   

/*
    Declare variable names for the led pins. The red led is connected to pin 1 and the
    green led is connected to pin 7.

    const - the variable has a constant value that can not change during the course of the program.
    int - the variable is an integer between -32768 to 32767
*/

const int redLED = 1;
const int greenLED = 7;

void setup()
{                
  OrangutanLCD::print("Battery");
  OrangutanLCD::gotoXY(0,1);
  OrangutanLCD::print(bat);
  OrangutanLCD::print("mV");
  
/*
    The command pinMode is used to configure the I/O pin as either input or output.
    When a pin is set to INPUT, the state of the pin, either HIGH or LOW, is typically
    checked by the program to see if an action, like a button push, has occurred. 
    When a pin is set to OUTPUT, it is typically used to provide an active signal to the
    component, e.g. an LED or a sensor, that is connected to it. When in OUTPUT mode, the pin
    is able to act as a current source and can be used to power small components such as LEDs.

    When a pin is set to output, the command digitalWrite can be used to either set its 
    digital state LOW or HIGH.
    
*/

  pinMode(redLED, OUTPUT);        // Set LED pins to OUTPUT
  pinMode(greenLED, OUTPUT);  
  
  digitalWrite(redLED, LOW); 
  digitalWrite(greenLED, LOW);
}


// The commands in this loop will repeat over and over and over and...

void loop()
{
  digitalWrite(redLED, HIGH);          // turn red led on
  digitalWrite(greenLED, LOW);         // turn green led off 
  delay(250);                          // pause for 250 ms
  digitalWrite(redLED, LOW);           // turn red led off
  digitalWrite(greenLED, HIGH);        // turn green led on
  delay(250);                          // pause for 250 ms
}
   
//**************************** End of Program ***************************  

counter on tumblr
Č
ċ
Daniel Sullivan,
Jul 26, 2011, 8:59 AM
Comments