/*
blink an LED at a rate set by the position of a potentiometer
*/
/*
reads the voltage on an analog pin (A0) and flashes an LED at a propor‐
tional rate to the value returned from the analogRead function.
*/
//#include <Arduino.h>
#define LED_Pin 12
#define Pot_Meter A0
//void blink(void); // function decleration
uint16_t blinkDelay = 0; // blink delay stored in this variable
void setup()
{
Serial.begin(9600); // Initialize serial port to send and receive at 9600 baud
pinMode(LED_Pin, OUTPUT); // set this pin as output
pinMode(Pot_Meter, INPUT); // set A0 as analog input
}
void loop()
{
blinkDelay = analogRead(Pot_Meter); // read the voltage on the pot
Serial.println(blinkDelay);
digitalWrite(LED_Pin, HIGH); // turn the ledPin on
delay(blinkDelay); // blink rate set by pot value (in milliseconds)
digitalWrite(LED_Pin, LOW); // turn the ledPin off
delay(blinkDelay); // turn led off for same period as it was turned on
}
/*// blink the LED with the on and off times determined by blinkDelay
void blink()
{
digitalWrite(LED_Pin, HIGH);
delay(blinkDelay); // delay depends on blinkDelay value
digitalWrite(LED_Pin, LOW);
delay(blinkDelay);
}
*/