OpticalSensor \ Learning \ Wiring ALPHA 1.0
Author: Hernando Barragán
Description: Wiring is an electronic sketchbook and hardware electronics for developing ideas. It is a context for learning fundamentals of computer programming and prototyping with electronics within the context of the electronic arts.
Keywords: Wiring, Processing, Interactive Media, Electronic Arts, Programming, C, C++, Hernando Barragán

Search wiring.org.co:

This example is for Wiring version 0023+. If you have a previous version, use the examples included with your software. If you see any errors or have comments, please let us know.

Transmissive optical sensor without aperture Vishay TCST1000/TCST2000 by Diana Fernandez
Demonstrates how to use a transmisive optical sensor. This sensor is used in mechanisms to detect when the gap in the top is blocked by an object. When the sensor detects an interruption the Wiring onboard LED is turned on.

    int sensorSwitch = 1;  // digital pin to attach the switch
    int sensorLED = 0;     // sensor LED
    int boardLED = 48;     // Wiring onboard LED

    void setup()
    {
      pinMode(sensorSwitch, INPUT);   // sets digital pin 1 as input
      pinMode(sensorLED, OUTPUT);     // sets digital pin 0 as output
      pinMode(boardLED, OUTPUT);      // sets digital pin 48 as output
      digitalWrite(sensorLED, HIGH);  // turns ON the sensor LED
    }

    void loop()
    {
      // make the onboard LED to show the sensor status
      digitalWrite(boardLED, digitalRead(sensorSwitch));
    }