Hi everybody so I have this project I am working on it is a ventilator
so far so good but for example I do not have like a O2 tank so I am going to simulate it with a led and for that idea I have this simple sketch about increasing and decreasing the LED light with 2 buttons
int button1 = 4;
int button2 = 3;
int buttonVal1;
int buttonVal2;
int LEDbright = 0;
int led = 8;
int buzz = 13;
void setup() { // put your setup code here, to run once:
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
pinMode(led, OUTPUT);
pinMode(buzz, OUTPUT);
Serial.begin(9600);
}
void loop() { // put your main code here, to run repeatedly:
buttonVal1 = digitalRead(button1);
buttonVal2 = digitalRead(button2);
Serial.print("button 1 = ");
Serial.print(buttonVal1);
Serial.print(", ");
Serial.print("button 2 = ");
Serial.println(buttonVal2);
delay(250);
if (buttonVal1 == 0){
LEDbright = LEDbright + 5;
}
if (buttonVal2 == 0){
LEDbright = LEDbright - 5;
}
if (LEDbright > 255){
LEDbright = 255;
digitalWrite(buzz, HIGH);
delay(100);
digitalWrite(buzz, LOW);
}
if (LEDbright < 0){
LEDbright = 0;
digitalWrite(buzz, HIGH);
delay(100);
digitalWrite(buzz, LOW);
}
analogWrite(led, LEDbright);
}
What I want is once I connect my LCD I want that when the LED is completely turned off for it to be equal to 21% and as I gradually increase brightness for it to go up to 100%
so im not sure how to do the math for this to work if anybody has any tips thanks.