Skip to content

Instantly share code, notes, and snippets.

@RuBiCK
Last active July 7, 2017 15:36
Show Gist options
  • Save RuBiCK/25bc35f11cce7d7669583e5fb26e9ae4 to your computer and use it in GitHub Desktop.
Save RuBiCK/25bc35f11cce7d7669583e5fb26e9ae4 to your computer and use it in GitHub Desktop.
Arduino Power control for turning on an arduino with a press button and power off with a continuous press
#define POWERCONTROL 2
#define POWERBUTTON 9
#define PULSETIME 3000
void setup() {
// put your setup code here, to run once:
pinMode(POWERCONTROL, OUTPUT);
digitalWrite(POWERCONTROL, HIGH);
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
pinMode(POWERBUTTON, INPUT);
digitalWrite(POWERBUTTON, LOW);
}
void check_power()
{
static long timer = 0;
if (digitalRead(POWERBUTTON))
{
if (timer == 0)
timer = millis();
if (timer + PULSETIME <= millis())
{
digitalWrite(POWERCONTROL, LOW);
digitalWrite(13, LOW);
}
}
else
timer = 0;
}
void loop() {
// put your main code here, to run repeatedly:
check_power();
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment