/* Fade and ReadAnalogVoltage to read the brightness of a led with a tsl257-lf photodetector amplifier */ int led = 9; // the PWM pin the LED is attached to int brightness = 0; // how bright the LED is int fadeAmount = 1; // how many points to fade the LED by (original: 5) // the setup routine runs once when you press reset: void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); pinMode(led, OUTPUT); } // the loop routine runs over and over again forever: void loop() { // read the input of the poti on analog pin 4, map it and give it to the led: int Poti = analogRead(A4); // map it to the range of the analog out: int Potimap = map(Poti, 0, 1023, 0, 255); // change the analog out value: analogWrite(A4, Potimap); // print the original Poti value to the Serial Monitor: Serial.print("Poti; "); Serial.print(Poti); /* // set the brightness of pin 9: analogWrite(led, brightness); Serial.print("brightness:"); Serial.print(brightness); Serial.print(" "); */ /* // change the brightness for next time through the loop: brightness = brightness + fadeAmount; // reverse the direction of the fading at the ends of the fade: if (brightness <= 0 || brightness >= 10) { // (original: >= 255) fadeAmount = -fadeAmount; } */ // wait for 30 milliseconds to see the dimming effect delay(300); // read the input of the OPT101 sensor on analog pin 2: int OPT101 = analogRead(A2); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V): // float voltage = sensorValue * (5.0 / 1023.0); // print out the value you read: Serial.print("; OPT101: "); Serial.println(OPT101); }