#define LED_Out_Pin 14
#define SW_In_Pin 15
#define VR_In_Pin 32
int VRvalue;
int FlashTime;
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);
// VRvalue = 100 = 3.3V , = 0 = 0V
// LED flashes from 1Hz to 5Hz by VR value
// 5 Hz delay is 200ms 1Hz delay is 1000ms
// map VRvalue 0 -> 100, make FlashTime delay 500ms to 100ms
// means total delay 1000ms to 200ms when VRvalue 0V -> 3.3V
FlashTime = map(VRvalue,0,100,500,100);
digitalWrite(LED_Out_Pin, HIGH);
delay(FlashTime);
digitalWrite(LED_Out_Pin, LOW);
delay(FlashTime);
}