// ARDUINO LESSON #1.2 - LED BRIGHTNESS CONTROL
//----------------------------------------------------------------------------------------------------------//
//This material was created by 123 Mechatronics (all rights reserved) as apart of a arduino lesson series,
//Enjoyed? Subscribe & Share w/ Friends ➤ https://www.youtube.com/channel/UCoKQptSRxU0hMAqcxwRpe6g/featured
//----------------------------------------------------------------------------------------------------------//
//IN THIS LESSON WE WILL BE GOING OVER HOW TO CONTROL THE BRIGHTNESS LEVELS OF AN LED WITH ARDUINO, WHILE EASY
//AT FIRST GLANCE THIS STAGE CAN BE TRICKY, DIGITAL PINS AND ANALOG PINS WHILE ALIKE IN SHAPE ARE DIFFERENT IN
//USE, TODAY WE WILL BE GOING OVER THOSE DIFFERENCES IN AND ADVANCE YOUR UDERSTANDING WITH ARDUINO!
//----------------------------------------------------------------------------------------------------------//
//
// 🢛🢛🢛 COPY & PASTE CODE BELOW 🢛🢛🢛
//
//----------------------------------------------------------------------------------------------------------//
const int RedLED = 11; //digital pin11 = RedLED
const int potentiometer = A0; //analog pinA0 = potentiometer
int SensorValue = 0; //define SensorValue (if called upon) with a "start" of 0
int OutputValue = 0; //define OutputValue (if called upon) with a "start" of 0
void setup() {
// put your setup code here, to run once:
pinMode(RedLED,OUTPUT); //RedLED (or pin11) is defined as an output
pinMode(potentiometer,INPUT); //RedLED (or pinA0) is defined as an input
}
void loop() {
// put your main code here, to run repeatedly:
int SensorValue = analogRead(potentiometer); //configure SensorValue to the analog readings of potentiometer
SensorValue = analogRead(potentiometer); //SensorValue starting from 0 (int SensorValue = 0;)
// as the potentiometer moves, the movements are mapped
// in analog numbers, These levels are stored for later use
OutputValue = map(SensorValue, 0, 1023, 0, 255); //OutputValue starting from 0 (int OutputValue = 0;)
// are than taken from our SensorValue and mapped in
// various ranges from (0-1023) and (0-255) values
analogWrite(RedLED, OutputValue); //RedLED (or pin11) is given a analog command to initiate
// various brightness levels depending on the potentiometer
delay(10); //delay void loop by 10 miliseconds (0.01 second)
}