#define LED_Out_Pin 25
#define SW_In_Pin 15
#define VR_In_Pin 36
int VRvalue;
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);
if (VRvalue > 30)
{
// Flash at 5Hz (every 100ms)
digitalWrite(LED_Out_Pin, HIGH);
delay(100);
digitalWrite(LED_Out_Pin, LOW);
delay(100);
}
else
{
// Flash at 1Hz (every 1000ms)
digitalWrite(LED_Out_Pin, HIGH);
delay(1000);
digitalWrite(LED_Out_Pin, LOW);
delay(1000);
}
}