Skip to content

Instantly share code, notes, and snippets.

@mmcev106
Created February 10, 2017 02:06
Show Gist options
  • Save mmcev106/8cf94cd26848d74cb1e62d42f8eb2a91 to your computer and use it in GitHub Desktop.
Save mmcev106/8cf94cd26848d74cb1e62d42f8eb2a91 to your computer and use it in GitHub Desktop.
const int BUTTON = 2;
const int LED = 3;
const int BLINK_ON_INCREMENT = 50;
const int BLINK_PAUSE_INCREMENT = 75;
const int RING_TIME = 5000;
void setup() {
pinMode(BUTTON, INPUT_PULLUP);
pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);
Serial.begin(9600);
}
void loop() {
if(digitalRead(BUTTON) == LOW){
buttonPushed();
}
}
void buttonPushed() {
Serial.println("button pressed");
unsigned long endTime = millis()+RING_TIME;
do{
shortBlink();
shortBlink();
longBlink();
longBlink();
delay(250);
Serial.println("millis");
Serial.println(millis());
Serial.println("endTime");
Serial.println(endTime);
Serial.println("");
} while(millis() < endTime);
}
void longBlink() {
blink(BLINK_ON_INCREMENT, BLINK_PAUSE_INCREMENT*2);
}
void shortBlink() {
blink(BLINK_ON_INCREMENT, BLINK_PAUSE_INCREMENT);
}
void blink(int onTime, int offTime) {
digitalWrite(LED, HIGH);
delay(onTime);
digitalWrite(LED, LOW);
delay(offTime);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment