Skip to content

Instantly share code, notes, and snippets.

@Ryanhu1015
Created May 30, 2017 06:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ryanhu1015/855ce5dc9b403c91e5808840b4812fd8 to your computer and use it in GitHub Desktop.
Save Ryanhu1015/855ce5dc9b403c91e5808840b4812fd8 to your computer and use it in GitHub Desktop.
button_pratice
int ledState = LOW;
int buttonState;
int buttonpin = 2;// pin for button
int ledpin = 5;// pin for led
int mapin = 6;// pin for motor
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 200;
void setup() {
Serial.begin(115200);
pinMode(buttonpin, INPUT_PULLUP);
pinMode(ledpin, OUTPUT);
pinMode(mapin, OUTPUT);
}
void loop()
{
int i, k;
int reading = digitalRead(buttonpin);
int currenttime = millis();
Serial.println(reading);
if ((currenttime - lastDebounceTime) > debounceDelay)
{
lastDebounceTime = currenttime;
if (reading == LOW)
ledState = !ledState;
}
//.
//.
//.
//.
//there are still bunch of code about how to let led and motor to work with pwm
//but it's not the point so skip it
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment