Light Detection and Measurement: Dr. Eng. Endrowednes Kuantama
Light Detection and Measurement: Dr. Eng. Endrowednes Kuantama
ARDUINO CODING
SENSOR
#define ledPin 13
#define potPin // select the input pin for the potentiometer
int val;
void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT
}
void loop() {
val = analogRead(potPin); // read the value from the sensor
Description
• Writes an analog value (PWM wave) to a pin. Can be used to light a LED at varying
brightnesses or drive a motor at various speeds.
• After a call to analogWrite(), the pin will generate a steady square wave of the specified
duty cycle until the next call to analogWrite() (or a call to digitalRead() or digitalWrite() on
the same pin). The frequency of the PWM signal is approximately 490 Hz.
• On most Arduino boards (those with the ATmega168 or ATmega328), this function works on
pins 3, 5, 6, 9, 10, and 11. On the Arduino Mega, it works on pins 2 through 13. Older
Arduino boards with an ATmega8 only support analogWrite() on pins 9, 10, and 11.
• The Arduino Due supports analogWrite() on pins 2 through 13, plus pins DAC0 and DAC1.
Unlike the PWM pins, DAC0 and DAC1 are Digital to Analog converters, and act as true
analog outputs.
The bottom line is that you call analogWrite()
with just the pin of interest and a duty cycle
value that ranges from 0 (off) to 255 (fully on).
ARDUINO CODING
void setup()
{
pinMode(illumination_output, OUTPUT); //config. pin 0 for dig. output
}
void setup()
{
for (i = 0; i < num_pins; i++) // the array elements are numbered from 0 to num pins - 1
pinMode(pins[i], OUTPUT); // set each pin as an output
}
void loop()
{
for (i = 0; i < num_pins; i++)
{ // loop through each pin...
digitalWrite(pins[i], HIGH); // turning it on,
delay(timer); // pausing,
digitalWrite(pins[i], LOW); // and turning it off.
}