CPP 231
Led button millis By hightechrobo on 27th January 2024 07:18:09 AM
  1. /*
  2. Hightechrobo learn
  3. by Arian
  4. */
  5.  
  6. #define button 4
  7. #define led 3
  8. bool a = false;
  9. int lastm = 0 ;
  10. int nowm = 0 ;
  11. int b = 0 ;
  12. void setup() {
  13.   // put your setup code here, to run once:
  14. //pinMode(led,OUTPUT);
  15. pinMode(button,INPUT_PULLUP);
  16. }
  17. void loop() {
  18.   // put your main code here, to run repeatedly:
  19.  
  20.   if(digitalRead(button) == 0 and a == 0){
  21.     a = 1;
  22.     lastm = millis();
  23.     b = 255;      
  24.     while(digitalRead(button) == 0){
  25.           analogWrite(led,b);
  26.           nowm = millis();
  27.           if(nowm - lastm > 500)
  28.           {
  29.             lastm = millis();
  30.             b = b - 50 ;              
  31.           }
  32.     if(b <= 0 )
  33.     a = 0 ;        
  34.     }
  35.     }
  36.  
  37. else if(digitalRead(button) == 0 and a == 1){
  38.   a = 0;
  39.  
  40.     while(digitalRead(button) == 0){
  41.           analogWrite(led,0);
  42.     }
  43.    
  44.     }
  45.    
  46. }

Hightechrobo bin is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.