Created
January 17, 2022 07:10
-
-
Save joshua-8/eef038567ccb52a37f58c06456d38f38 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* It is an inexpensive device to motivate children to exercise on a stationary bike; when the children pedal a bike, a movie or song they have chosen plays. | |
* It uses a magnet sensor to measure the speed of the pedal or crank of an exercise machine, and has a knob for changing what threshold is fast enough. | |
* The microcontroller emulates a keyboard and sends a space key press to start or stop any video or music playing on a computer. | |
* Use with a Digispark http://digistump.com/products/1, knob, and magnet sensor. | |
* by Joshua, 2015 | |
*/ | |
#include "DigiKeyboard.h" | |
boolean paused = true; | |
unsigned long timeSinceCrank = 10000000; | |
int speedShow = 1; | |
boolean magt; | |
boolean magtLas; | |
void setup() { | |
pinMode(2, INPUT);//knob | |
pinMode(0, INPUT);//sensor | |
pinMode(1,OUTPUT);//light-built in | |
digitalWrite(1,HIGH);//light | |
DigiKeyboard.delay(1400); | |
digitalWrite(1,LOW);//light | |
DigiKeyboard.delay(300); | |
} | |
void loop() { | |
analogWrite(1,speedShow);//light | |
magt = !digitalRead(0); | |
if (magt == true && magtLas == true) { | |
timeSinceCrank = 1; | |
magtLas = false; | |
} | |
if (magt == false) { | |
magtLas = true; | |
} | |
if (timeSinceCrank < 1000000) { | |
timeSinceCrank=timeSinceCrank+map(analogRead(1/*knob*/),0,1023,900,60); | |
} | |
speedShow = constrain(map(constrain(timeSinceCrank,0,1100000),0,1000000,255,0),0,255); | |
if (speedShow > 3 && paused == true) { | |
paused = false; | |
DigiKeyboard.write(" "); | |
} | |
if (speedShow < 2 && paused == false) { | |
paused = true; | |
DigiKeyboard.write(" "); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment