Skip to content

Instantly share code, notes, and snippets.

@jimmont
Last active November 9, 2015 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimmont/dd43de77a551a66546ea to your computer and use it in GitHub Desktop.
Save jimmont/dd43de77a551a66546ea to your computer and use it in GitHub Desktop.
bean bike cycling project
/*
Bean Loader v 1.9.3 build 1219
Arduino v 1.6.5
previous problem:
when I input via D5 using a reed switch (cyclometer head+mount)
and smack the sensor with a magnet it often increments by a step of 5 or so,
so too much suggesting the interrupt occurs several times instead of the expected single hit
for that pass of the magnet by the reed switch
update:
Talking with the expert Malcolm we're pretty certain the reed switch is bouncing internally
since it wasn't designed for this (to be hit with the magnet) but is intended to have the
magnet spin a few millimeters away on the wheel. So this isn't really a problem since it
never happens in real-world use. On the wheel it should actually send a signal once per
pass as-desired.
overall logic is:
the interrupt handles counting of cycles (of the wheel+magnet passing the reed switch)
the loop handles reporting of the count and zeros it again each loop
*/
#include <PinChangeInt.h>
#define CYCLOMETER_PIN 5
int cycles = 0;
uint8_t val = 0;
void setup() {
attachPinChangeInterrupt(CYCLOMETER_PIN,wheelCycled, CHANGE);
}
void wheelCycled(){
val = digitalRead(CYCLOMETER_PIN);
cycles++;
}
void loop() {
String output = String();
output = output + " cycles"+ cycles +" val" + val;
cycles = 0;
Serial.println(output);
Bean.sleep(300);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment