// Connected pins const int pressureSense = A0; const int button = 4; const int LED_orange = 5; // pin 5 is PWM (~) const int LED_white = 6; // pin 6 is PWM (~) // Usable variables int buttonState = 0; // store button press state for switching LED colors (0, 1) int pressureRaw = 0; // stores raw pressure data (~80 - ~450) int pressureConstrained = 0; // stores constrained pressure data (80-450) int brightness = 0; // stores LED brightness from mapped, constrained, pressure data (0-255) void setup() { // put your setup code here, to run once: Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: Serial.println(analogRead(pressureSense)); // shows raw pressure data for debugging // Process pressure input pressureRaw = analogRead(pressureSense); // store raw pressure value pressureConstrained = constrain(pressureRaw, 80, 450); // constrain pressure data to range of 80-450 brightness = map(pressureConstrained, 80, 450, 0, 255); // map pressure scale to brightness scale // Choose and control LEDs buttonState = digitalRead(button); // store current button state if (buttonState == 1) { // if button pressed, light orange LED analogWrite(LED_orange, brightness); } else { //otherwise, white LED analogWrite(LED_white, brightness); } delay(50); }