Examples - Sensorboard - Infrared
Infrared
This Example shows the use of an Infrared Sensor.
/************************************************************************************************** * * Infrared Sensor SHARP * * Version: 1.0.0 - September 2008 * Author: Etienne Ribeiro / tutorial assistant caad / eribeiro[at]ethz.ch * Supervisor: Christoph Wartmann / chair for caad - ETH Zürich / wartmann[at].arch.ethz.ch * * Desc: Shows the use of an Infrared Sensor on analog pin. * ***************************************************************************************************/ // Const static int pinAnalogIn = 0; static int pinInMaxValue = 500; static int pinOut[] = {24, 25, 26, 27, 28}; static int pinOutCount = 5; static boolean enableSerial = true; // Setup void setup() { // LED (2 * blink) pinMode(48, OUTPUT); digitalWrite(48, HIGH); delay(200); digitalWrite(48, LOW); delay(200); digitalWrite(48, HIGH); // Serial (Print to serial if enableSerial = true) if (enableSerial == true) Serial.begin(9600); // Pin Mode for (int iPin = 0;iPin < pinOutCount;iPin++) { pinMode (pinOut[iPin], OUTPUT); } } // Loop void loop() { // Read: int val = analogRead(pinAnalogIn); // LED on/off: for (int iPin = 0;iPin < pinOutCount;iPin++) { if (pinInMaxValue / pinOutCount * (iPin + 1) > val) digitalWrite(pinOut[iPin], HIGH); else digitalWrite(pinOut[iPin], LOW); } // Debug: if (enableSerial == true) { Serial.print(" Val: "); Serial.print(val, DEC); Serial.print(" (Pin "); Serial.print(pinAnalogIn, DEC); Serial.print(") "); Serial.println(""); } // Wait: delay(50); }