Things used in this project

Hardware components:
Magnetic reed switch
×1
USB to micro-USB cable or adapter
×1
A000057 featured
Arduino Leonardo
×1
Mfr 25frf52 10k sml
Resistor 10k ohm
×1

Code

arduino_software___google_maps_street_view.Plain text
arduino_software___google_maps_street_view.
 /* 
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; 
}

Credits

E652175b169fbe7c0ca9b1cc7b02b4a3
jadkins
1 project • 1 follower
Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaBlog