//Student name: Ngan Hoi Sing
//Class: EG524403-1A
//Student no.: 230292338
//https://wokwi.com/projects/382443992301583361
// Program: Ex6B_Analog_Input-E.ino
/*
Exercise 6 Q2
Change the program of Ex6B_Analog_Input-E to:
1. LED flashes at 5Hz at 3.3V to
2. LED flashes at 1Hz at 0V
*/
#define LED_Out_Pin 25 //Set output position in pin 25
#define SW_In_Pin 15 //Set input position in pin 15
#define VR_In_Pin 34 //Set VR input postion in pin 34
int VRvalue; //Set the VR value
void setup()
{
// Initialize serial port
Serial.begin(115200);
// Set pins
pinMode(LED_Out_Pin, OUTPUT);
pinMode(SW_In_Pin, INPUT_PULLUP);
}
void loop()
{
// Reading
VRvalue = analogRead(VR_In_Pin);
// Display
Serial.print("Raw Sensor reading: ");
Serial.print(VRvalue);
VRvalue = map(VRvalue, 0, 4095, 0, 100); // scale it
Serial.print("\tScaled Sensor reading: ");
Serial.println(VRvalue);
// Set when VRValue is zero or not, The LED flashes 1Hz
if (VRvalue == 0){
digitalWrite(LED_Out_Pin, HIGH);
delay(1000);
digitalWrite(LED_Out_Pin, LOW);
delay(1000);
}
// Set when VRValue is 3.3V, The LED flashes 5Hz
else if (VRvalue >= 3.3){
digitalWrite(LED_Out_Pin, HIGH);
delay(200);
digitalWrite(LED_Out_Pin, LOW);
delay(200);
}
}