
the modulo function gives you the remainder of checking the modulo of the button push counter. turns on the LED every four button pushes by save the current state as the last state, if the current state is LOW then the button Serial.print("number of button pushes: ") if the current state is HIGH then the button if the state has changed, increment the counter

compare the buttonState to its previous state Myservo.attach(9) //attach servo to pin 9 Int lastButtonState = 0 // previous state of the button Int buttonState = 0 // current state of the button Int buttonPushCounter = 0 // counter for the number of button presses
ARDUINO PWM PIN 11 VARSPEEDSERVO CODE
This example code is in the public domain.Ĭonst int buttonPin = 2 // the pin that the pushbutton is attached toĬonst int ledPin = 13 // the pin that the LED is attached to * LED attached from pin 13 to ground (or use the built-in LED on * 10K resistor attached to pin 2 from ground
ARDUINO PWM PIN 11 VARSPEEDSERVO HOW TO
This example shows how to detect when a button or button changes from off to on State change detection, or edge detection. Often, you don't need to know the state of a digital input all the time,īut you just need to know when the input changes from one state to another.įor example, you want to know when a button goes from OFF to ON. I'm assuming it's a simple mistake on my part.

But I'm getting a large error when it is compiled, its as if the library isnt there, but it is. I'm butchering the "edge detection" code to sense when the button is pushed, and to move a single servo appropriately, see below. Lamp is turned off, things move back to original position. So the lamp will turn on, things move to one position.

I'll be using the Arduino to move about 6 servos when a button is pushed/switch flicked to move components on a floor-standing lamp.

Maybe you can help me with my first project. First off, HI! pretty new to this but eager to make some stuff.
