3Pi Projects‎ > ‎

Project 3 - Push a Button

/* ############################################################################ */
/* ##                                                                        ## */
/* ##                    Project 3                                           ## */
/* ##                    Push a Button                                       ## */
/* ##                    https://sites.google.com/site/3piprojects/          ## */
/* ##                                                                        ## */
/* ##                    Daniel J. Sullivan                                  ## */
/* ##                    July 17, 2011                                       ## */
/* ##                                                                        ## */
/* ############################################################################ */
   
/*
    1. Use the same initial code as in Project 2.
    2. Assign pinModes for the on board red and green LEDs.
    3. Use a while loop to wait for the left button A to be pushed.
    3. Place a blink routine in the main loop section of the program.
*/

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

int bat = OrangutanAnalog::readBatteryMillivolts();   

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

/*
  The 3Pi has three buttons. 
      button A is on Pin 9.
      button B is on Pin 12.
      button C is on Pin 13.
  Declare a constant integer variable for button A
*/

const int buttonA = 9;
  
void setup(){
  
  pinMode(redLED, OUTPUT);
  pinMode(greenLED, OUTPUT);
  
  digitalWrite(greenLED, LOW);
  digitalWrite(greenLED, LOW);
  
/*
   There are 20K pull-up resistors built into the Atmega chip. When these are set the
   pins will read HIGH when they are read.
   These built-in pullup resistors are accessed in the following manner:
   pinMode(pin, INPUT);
   digitalWrite(pin, HIGH);   
*/  
  
  pinMode(buttonA, INPUT);            // set pin to input
  digitalWrite(buttonA, HIGH);        // enable pullup resistors
  
 // Display battery voltage on LCD
  
  OrangutanLCD::clear();
  OrangutanLCD::print(bat);
  OrangutanLCD::print("mv");
  OrangutanLCD::gotoXY(0,1);
  OrangutanLCD::print("Next..."); 
  
// This is an empty While Loop that waits for button A to be pushed.
// When the button is pushed the digital pin will be connected to ground (GND) and go LOW.
  
  while (digitalRead(buttonA) == HIGH)
  {    
  }

// Once a button is pushed, the LCD screen displays new message, and the program proceeds.

    OrangutanLCD::clear();
    OrangutanLCD::print("Let's");
    OrangutanLCD::gotoXY(0,1);
    OrangutanLCD::print("Blink!"); 
}

// Main Loop of program is used to flash the green and red LEDs at a rate of 250 ms.

void loop()
{
  digitalWrite(redLED, HIGH);
  digitalWrite(greenLED, LOW);
  delay(250);
  digitalWrite(redLED, LOW);
  digitalWrite(greenLED, HIGH);
  delay(250);
    
}
   
//**************************** End of Program ***************************
  

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