// Define a pin that we'll place the FSR on
// Remember to add a 10K Ohm pull-down resistor too.
int fsrPin = A0;
// Create a variable to hold the FSR reading
int fsrReading = 0;
// Define a pin that we'll place the pot on
int potPin = A5;
// Create a variable to hold the pot reading
int potReading = 0;
// Define a pin we'll place an LED on
int ledPin = D2;
//int ledBluePin = D4;
// Create a variable to store the LED brightness.
int ledBrightness = 0;
// int ledBrightness = 0;
void setup() {
// Set up the LED for output
pinMode(ledPin, OUTPUT);
// add this line...
//pinMode( buttonPin , INPUT_PULLUP); // sets pin as input
}
void loop() {
// Use analogRead to read the photo cell reading
// This gives us a value from 0 to 4095
fsrReading = analogRead(fsrPin);
// Map this value into the PWM range (0-255)
// and store as the led brightness
ledBrightness = map(fsrReading, 0, 4095, 255, 0);
// fade the LED to the desired brightness
analogWrite(ledPin, ledBrightness);
// wait 1/10th of a second and then loop
//delay(100);
// First... On
//digitalWrite(ledPin, HIGH);
delay(250);
// Now... Off
digitalWrite(ledPin, LOW);
delay(250);
// rinse + repeat
// Use analogRead to read the potentiometer reading
// This gives us a value from 0 to 4095
potReading = analogRead(potPin);
// Map this value into the PWM range (0-255)
// and store as the led brightness
ledBrightness = map(potReading, 0, 4095, 0, 255);
// fade the LED to the desired brightness
analogWrite(ledPin, ledBrightness);
// wait 1/10th of a second and then loop
delay(100);
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .