milanbranch.com
  • Home
  • Trackplan
  • RMC Arduino Lighting
  • Home
  • Trackplan
  • RMC Arduino Lighting
Dim
​/*
Dim
*/
// the setup function runs once when you press reset or power the board
int ledPin = 9; // LED connected to digital pin 9
int analogPin = 2; // potentiometer connected to analog pin 3
int val = 0; // variable to store the read value
void setup() {
pinMode(3, OUTPUT); // sets the pin as output
}
void loop() {
analogWrite(3, 255); // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
}
Picture
To dim an LED, use one of the six pins shown on the Qwiiic board. Type in the pin number used where the yellow indicates, and enter a value between 0-255 shown in blue. The red circle shows an amber rectangle that may appear when the code is pasted in place. Delete any that appear.

Blink
/*
Blink
*/
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(2, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(2, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Picture
To blink an LED, type in the pin number used where the yellow indicates, and enter a time value shown in blue. Example: 1000 equals one-second; 1500 equals 1.5 seconds, etc. 

On  Off
/*
On Off
*/
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(2, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level)
}
Picture
To turn an LED on or off, type in the pin number used where the yellow indicates, and enter HIGH (on) or LOW (off) in the blue.

BONUS:  Blink + Dim
​// The setup function runs once when you press reset or power the board
void setup() {
pinMode(3, OUTPUT);
}
// The loop function runs over and over again forever
void loop() {
analogWrite(3, 128); // half brightness
delay(1000);
analogWrite(3, 0); // Off
delay(1000);
}
Site powered by Weebly. Managed by pair Domains