/* Blink Turns on an LED on for one second, then off for one second, repeatedly. Most Arduinos have an on-board LED you can control. On the Uno and Leonardo, it is attached to digital pin 13. If you're unsure what pin the on-board LED is connected to on your Arduino model, check the documentation at http://www.arduino.cc This example code is in the public domain. modified 8 May 2014 by Scott Fitzgerald */ #define BUTTON_PIN 3 #define LED_PIN 7 int val; int fib1 = 0; int fib2 = 1; unsigned long current_time = 0; bool is_high = false; unsigned long last_time = 0; // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin 13 as an output. pinMode(LED_PIN, OUTPUT); pinMode(BUTTON_PIN, INPUT); //set pin 3 as an input } void tick(){ current_time = millis() - last_time; } void reset_timer(){ last_time = millis(); current_time = 0; } // the loop function runs over and over again forever void loop() { //only do stuff while pin 3 is on if (!val && digitalRead(BUTTON_PIN)){ int temp = fib1; fib1 = fib2; fib2 += temp; } val = digitalRead(BUTTON_PIN); tick(); if (current_time > 1000 * fib2){ if (!is_high){ digitalWrite(LED_PIN, HIGH); // turn the LED on (HIGH is the voltage level) is_high = true; }else{ digitalWrite(LED_PIN, LOW); // turn the LED off is_high = false; } reset_timer(); } /* delay(1000 * fib2); // wait for a second digitalWrite(LED_PIN, LOW); // turn the LED off by making the voltage LOW delay(1000 * fib2); // wait for a second */ }