Created
September 21, 2013 22:25
-
-
Save oksuz/6654794 to your computer and use it in GitHub Desktop.
Arduino led brightness control
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int ledPin = 9; | |
const int switchPin = 2; | |
int buttonState = 0; | |
int multiplier = 0; | |
float buttonPressedCounter = 0.0; | |
void setup() { | |
pinMode(ledPin, OUTPUT); | |
pinMode(switchPin, INPUT); | |
Serial.begin(9600); | |
} | |
void loop() { | |
buttonState = digitalRead(switchPin); | |
if (buttonState == HIGH) { | |
if (buttonPressedCounter > 2) { | |
buttonPressedCounter = 0; | |
multiplier += 5; | |
Serial.print("MULTIPLIER : "); | |
Serial.println(multiplier); | |
if (multiplier > 220) { | |
multiplier = 0; | |
analogWrite(ledPin, multiplier); | |
} else { | |
analogWrite(ledPin, multiplier); | |
} | |
buttonPressedCounter = 0; | |
} else { | |
Serial.print("Button Press Counter : "); | |
Serial.println(buttonPressedCounter); | |
buttonPressedCounter++; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment