Skip to content

Instantly share code, notes, and snippets.

@oksuz
Created September 21, 2013 22:25
Show Gist options
  • Save oksuz/6654794 to your computer and use it in GitHub Desktop.
Save oksuz/6654794 to your computer and use it in GitHub Desktop.
Arduino led brightness control
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