Hello everyone,
I had a long detailed message about my problem but it was all wiped out due to a little too large image.
So here's the short story:
Arduino Micro controlling LED's. LED's should only lit up once button is kept pressed for set amount of time. LED's lit up over set time to set brightness. LED's shut down immediately after button is pressed again for set (shorter) time.
Problem:
LED lits up to near full brightness once power is turned on and first button press will only make LED even brighter over set time. Second press of button will make LED dim back to original brightness. LED never is shut down.
I'm a fresh electrician and have no clue or understanding on coding. This code was written to me by a pro almost a year ago and they have no interest in my peril anymore. I've only resently progressed in my project into needing this code to work.
I hope someone sees/finds something I've missed.
Thank you!
Parts I've used (images are rather soddy so thought this might help):
PN2222
L7805CV
C 0,1mF 2x
R 1k ohm
R 150 ohm (for each 5 LED's) forgot to write these into the picture.
Also the image has cut out a bit: (Button - & LED+ from PWR (LED has 150 ohm R each)).
P.S.
I tried to look for the correct section for this initial posting of mine, I'm terribly sorry if it's completely bonkers and all over the place. Please move it if deemed necessary.
int LED = 3;
int button = 4;
int brightness = 0;
int maxBrightness = 255;
long buttonTimer = 0;
long buttonTime = 1000;
boolean buttonActive = false;
boolean longPressActive = false;
boolean LedActive = false;
void setup() {
// put your setup code here, to run once:
pinMode(LED, OUTPUT);
pinMode(button, INPUT_PULLUP);
}
void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(button) == LOW){
if(buttonActive == false){
Serial.println("Button pressed");
buttonActive = true;
buttonTimer = millis();
if(LedActive == true){
LedActive = !LedActive;
digitalWrite(LED, LedActive);
brightness = 0;
}
}
}else{
buttonActive = false;
longPressActive = false;
buttonTimer = 0;
}
if((buttonActive == true) && (millis() - buttonTimer > buttonTime) && (longPressActive == false)){
longPressActive = true;
Serial.println("Longpress active");
LedActive = !LedActive;
}
if(LedActive == true){
if(brightness < maxBrightness){
analogWrite(LED, brightness);
brightness = brightness + 5;
delay(60);
}
}
}