Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Initilize Vars
- const int ButtonUp = 12;
- const int ButtonDown = 11;
- boolean lastButtonUp = LOW;
- boolean lastButtonDown = LOW;
- boolean currentButtonUp = LOW;
- boolean currentButtonDown = LOW;
- int ledState = LOW;
- unsigned long previousMillis = 0;
- long Hz = 9;
- long interval = 1000/(2);
- void setup(void) {
- // put your setup code here, to run once:
- Serial.begin(9600);
- pinMode(ButtonUp, INPUT_PULLUP);
- pinMode(ButtonDown, INPUT_PULLUP);
- pinMode(2,OUTPUT);
- }
- void loop() {
- buttonPushed();
- blinkLED(interval/Hz);
- }
- void buttonPushed(){
- //Check if Up Button is pushed
- currentButtonUp = digitalRead(ButtonUp);
- if(lastButtonUp == LOW && currentButtonUp == HIGH && Hz < 999)
- {
- Hz = Hz + 1;
- //Serial.println(Hz);
- }
- lastButtonUp = currentButtonUp;
- //Check if Down Button is pushed
- currentButtonDown = digitalRead(ButtonDown);
- if(lastButtonDown == LOW && currentButtonDown == HIGH && Hz > 0)
- {
- Hz = Hz - 1;
- //Serial.println(Hz);
- if (Hz == 0){
- ledState= HIGH;
- }
- }
- lastButtonDown = currentButtonDown;
- }
- void blinkLED(const long interval) {
- //Serial.println(interval);
- unsigned long currentMillis = millis();
- if (currentMillis - previousMillis >= interval){
- previousMillis = currentMillis;
- if (ledState == LOW){
- ledState = HIGH;
- }
- else {
- ledState = LOW;
- }
- }
- digitalWrite(2, ledState);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement