//Student name: Ngan Hoi Sing
//Class: EG524403-1A
//Student number: 230292338
//https://wokwi.com/projects/382613722133605377
// Program: Ex6C_Analog_Output-E.ino
/*
Exercise 6 Q3
Change the program of Ex6C_Analog_Output-E to:
1. Fully turn on the LED at 3.3V from VR
2. Dim the LED to zero intensity at 0V from VR
*/
#define LED_Out_Pin 25 //Set the led to be output
#define VR_In_Pin 34 //Set VR to be input
int VRvalue; // Set the value of VR
int fadevalue;
void setup()
{
// Initialize serial port
Serial.begin(115200);
// Set pins
pinMode(LED_Out_Pin, OUTPUT);
pinMode(VR_In_Pin, INPUT);
}
void loop()
{
// Reading
VRvalue = analogRead(VR_In_Pin);
// Display
Serial.print("Raw Sensor reading: ");
Serial.println(VRvalue);
//Set when voltage is, the LED flashes frequency is
fadevalue = map(VRvalue, 0, 1023 , 0, 255);
analogWrite(LED_Out_Pin, fadevalue);
delay(1000);
}