/* Exercise Bike Interface to Google Maps Street View Based on Keyboard.Message Example Program. Sends a text string when a button is pressed. The circuit: * Magnetic reed switch attached from pin 2 to +5V * 10-kilohm resistor attached from pin 2 to ground created 24 Oct 2011 modified 27 Mar 2012 by Tom Igoe modified 24 June 2012 by Jeff Adkins This example code is in the public domain. http://www.arduino.cc/en/Tutorial/KeyboardButton */ //initialization of constants const int buttonPin = 2; // input pin for pushbutton int previousButtonState = HIGH; // for checking the state of a pushButton int counter = 0; // button push counter const int crankratio =5; // number of pedals that invokes a single "up arrow" int debounceFlag1 = 0; // debounce flag int debounceFlag2 = 0; // debounce flag // The debounce flags are two separate magnetic field inputs taken one after the other. // if they match, then the switch is assumed to have actually triggered. void setup() { // make the pushButton pin an input: pinMode(buttonPin, INPUT); // initialize control over the keyboard: Keyboard.begin(); } // Main Loop void loop() { // read the pushbutton: int buttonState = digitalRead(buttonPin); // if the button state has changed, if ((buttonState != previousButtonState) // and it's currently pressed: && (buttonState == HIGH)) { // set debounceflag1 = buttonState debounceFlag1 = buttonState; // delay 3 ms and read it again delay (3); debounceFlag2 = digitalRead(buttonPin); // if it still reads High after 3 ms delay if (debounceFlag1 = debounceFlag2); { // increment the button counter counter++; // keyboard print test //Keyboard.print(counter); if (counter>=crankratio){ counter = 0; // type out a message //Keyboard.print("You pressed the button "); //Keyboard.print(counter); //Keyboard.println(" times."); Keyboard.press(218); delay(100); Keyboard.release(218); delay(100); } } debounceFlag1 = 0; debounceFlag2 = 0; } // save the current button state for comparison next time: previousButtonState = buttonState; }