231a-af Arduino code

From CSclasswiki
Jump to: navigation, search

Return to Final Project Presentation.

/*
 * Analog Input
 *
 * Based off the example program written by DojoDave.
 * Turns on and off a light emitting diode(LED) connected to digital
 * pin 13.  The amount of time the LED will be on and off depends on
 * the value obtained by analogRead().
 *
 * http://www.arduino.cc/en/Tutorial/AnalogInput
 */

int irPin = 1;
int ledPin = 13;

void setup() {
  pinMode( ledPin, OUTPUT );
  pinMode( irPin, INPUT );
}

void loop() {
  if( analogRead( irPin ) > 100 ) {
    digitalWrite( ledPin, HIGH );
  } else {
    digitalWrite( ledPin, LOW );
  }
}