Arduino Ingress Hack Timer
Posted in Code, Hobbies, Tech
Forenoon watch, 7 bells (11:58 am)

I've been enjoying playing Ingress lately, but found myself in need of a 5-minute cool-down timer whilst hacking portals. Not wanting to exit the app and launch a separate timer on my Nexus 4, I went to my Arduino for an answer and came up with this solution: a 5-minute timer with a bare Arduino.

That's it, no extra parts necessary.

Using the Arduino's built-in LED on pin 13, After 3 minutes I start turning the LED off and on about once per second. At 4 minutes the blinking speeds up. At 4:30 it speeds up again. At 5 minutes the LED is on steady. Hit the reset button when you hack the portal and start over!

Plug the Arduino in and compile/upload the following code:

const int ledPin = 13;
int ledState = LOW;

unsigned long lastBlink = 0;

void toggleLEDState() {
  if(ledState == LOW) {
    ledState = HIGH;
  } else {
    ledState = LOW;
  }
}

void setup() {
  pinMode(ledPin, OUTPUT);
}

void loop() {
  unsigned long nowMillis = millis();
  
  if(nowMillis > 300000) {
    ledState = HIGH;
  } else if(nowMillis > 270000) {
    if(nowMillis - lastBlink > 200) {
      toggleLEDState();
      lastBlink = nowMillis;
    }
  } else if(nowMillis > 240000) {
    if(nowMillis - lastBlink > 500) {
      toggleLEDState();
      lastBlink = nowMillis;
    }
  } else if(nowMillis > 180000) {
    if(nowMillis - lastBlink > 1000) {
      toggleLEDState();
      lastBlink = nowMillis;
    }
  }
  
  digitalWrite(ledPin, ledState);
}
Leave a Comment »

Leave a Reply