Overall Circuit:
This is the input, sensor area.
Push Sensor
When you push the basic force resisting sensor the LED will light up.
This one will require you to push the push button and then as you place your finger closer to the photo cell the LED light will light up brighter.
The Code:
int sensePin = A0;
int ledPin = 9;
int ledPressPin= 8;
int pressPin = A2;
void setup () {
Serial.begin(9600);
pinMode (ledPin, OUTPUT);
pinMode (ledPressPin, OUTPUT);
}
void loop () {
//Serial.println (analogRead (sensePin));
Serial. println (analogRead (pressPin));
int valLight = analogRead (sensePin);
int valPress= analogRead (pressPin);
if (valPress > 0) digitalWrite(ledPressPin, HIGH);
else digitalWrite (ledPressPin, LOW);
valLight = constrain (valLight, 750, 900);
int ledLevel = map (valLight, 750, 900, 255, 0);
analogWrite (ledPin, ledLevel);
// if (val < 800) digitalWrite (ledPin, HIGH);
// else digitalWrite (ledPin, LOW);
}
Nice documentation!