- // Muhammadi
- #define button 2
- #define led 3
- void setup() {
- Serial.begin(9600);
- pinMode(button, INPUT_PULLUP);
- }
- bool flag = 0;
- int act = 0;
- int brightness = 255;
- void loop() {
- if(digitalRead(button) == 0){
- if(flag == 1){
- int time = millis();
- act = time;
- while(digitalRead(button) == 0){
- if(millis() - time > 400){
- Serial.print(brightness);
- time = millis();
- if(brightness > 40){
- brightness -= 40;
- }
- analogWrite(led, brightness);
- }
- }
- if(millis() - act < 400){
- analogWrite(led, 0);
- flag = 0;
- }
- }
- else{
- while(digitalRead(button) == 0){}
- brightness = 255;
- flag = 1;
- analogWrite(led, 255);
- }
- }
- }
Recent Pastes