Types:
Interfacing LEDs to the Arduino:
int ledPin = 12; // LED connected to digital pin 12 void setup() { pinMode(ledPin, OUTPUT); // sets the digital pin as output } void loop() { digitalWrite(ledPin, HIGH); // sets the LED on delay(1000); // waits for a second digitalWrite(ledPin, LOW); // sets the LED off delay(1000); // waits for a second } |
int value = 0; // variable to keep the actual value int ledPin = 9; // LED connected to digital pin 9 void setup() { pinMode(ledPin, OUTPUT); // sets the digital pin as output } void loop() { for ( value=0; value<=255; value+=5 ) { // fade in (from min to max) analogWrite( ledPin, value ); // sets the value (range from 0 to 255) delay( 30 ); // waits for 30 milli seconds to see the dimming effect } for ( value=255; value>=0; value-=5 ) { // fade out (from max to min) analogWrite( ledPin, value ); delay( 30 ); } } |
![]() | ©2004-2020 McGill University. All Rights Reserved. Maintained by Gary P. Scavone. |