Go Down

Topic: Virtual Cycling by controling the VLC Media Player (with sketch) (Read 1 time) previous topic - next topic

HasseBasse

Feb 26, 2013, 09:16 am Last Edit: Feb 26, 2013, 10:37 am by HasseBasse Reason: 1
By Hans Näsström
This is a Virtual Cycling VIDEO-CONTROLER connected to a reed-switch on your training/spinning -bike.
This program can control video playback speed on a VLC media player by emulating Hot-key´s for the player,
works only on ARDUINO LEONARDO systems. It controls speed from 40% to 200% and stops and pause if you stop pedaling.
At normal pedaling speed the video will play at 100% speed.
For this to work properly ---
1: Start the video with a suitable video and then set it in pause mode (key U).
2: Start (connect) the ARDUINO LEONARDI and wait 10 sec. for it to set up.
3: And away you go! - Start pedaling!

Set VLC-Hotkeys as follows,---- Tools--Preferences--Hotkeys-----
[Pause/Play]: Double click, set and save both Hotkey and Global, set to: the letter u
[Slower (fine)]: Double click, set and save both Hotkey and Global, set to: numpad 4
[Faster (fine)]: Double click, set and save both Hotkey and Global, set to: numpad 6
Save these settings and close the player for it to take effect.
A large number of virtual cycling videos can be downloaded from YouTube, my favorite is:
http://www.youtube.com/watch?v=FTmPk8qpxQA&playnext=1&list=PLXx7G1Mb0J8V4lAGyRzL2g07LBLqLHYZL&feature=results_main

You can download this video from this place, note the double ss before youtube…
[http://www.ssyoutube.com/watch?v=FTmPk8qpxQA&playnext=1&list=PLXx7G1Mb0J8V4lAGyRzL2g07LBLqLHYZL&feature=results_main]

You will need this hardware fixes:
Set a magnet on and a magnetic reed-switch by the trainer-bike´s wheel, closing only ONES every wheel turn,
(magnet north pole pointing towards the reed-switch).
Attached the reed-switch cables to Digital pin3 and Ground on the Arduino Leonardo.
Set a pull up resistor 100kOhm between +5V and Digital pin3
This software is free to use but on your one risk. Beware it will send keystrokes u, 4, and 6 now and then.
Happy Cycling/Training!



Code: [Select]


int videostep=1;
int steplevel=1;
int pause_run=0; // run = 1   pause = 0
int Rot = 0;  // Wheel rotation counter
int bike_wheel_rev = 0;
unsigned long time;
float cruise=61;      // ATTENTION!! Set this value to the number of wheelturns on YOUR bike during
                     // 4 sek and normal cruising speed (the video will go at 100% speed at this count)
void setup()
{

 time=millis();
 while ((time+5000)>millis()); {  } // time for system to settle, setting up Com port etc
 
 Serial.begin(9600);
 
 attachInterrupt(0, rpm, FALLING); // Set a pull up 10K resistor from 5V to Digital pin 3 (interupt 0).
 cli();            // Disable interrupts for now

 // initialize control over the keyboard:
 Keyboard.begin();
 
//Step down speed from 100% to 40%    
 int var = 0;
 while(var < 6){
 Keyboard.press('4'); delay(100); Keyboard.releaseAll();delay(100);
 var++;
}

}

void loop ()
{

 int Rot=0;  
 bike_wheel_rev = 0; //Set bike_wheel counter to 0
 sei(); //Enables interrupts
 delay (4000);        //count # bike wheel rev during 4 sec
 cli(); //Disable interrupts
 Rot = (bike_wheel_rev);   //Rot = revolutions during 4 sec

    if (Rot<20 && pause_run == 1)    {
    pause_run = 0;
    Keyboard.press('u'); delay(100); Keyboard.releaseAll(); delay(100);
 }
 if (Rot>19 && pause_run == 0)    {
   pause_run = 1;  
   Keyboard.press('u'); delay(100); Keyboard.releaseAll(); delay(100);
 }
 if (Rot<(cruise*0.4))   { steplevel=1;}  // Serial.println("1-#");    
 if (Rot>(cruise*0.5))   { steplevel=2;}  // Serial.println("2-##");        
 if (Rot>(cruise*0.6))   { steplevel=3;}  // Serial.println("3-###"); wheel speed at 50% video speed
 if (Rot>(cruise*0.7))   { steplevel=4;}  // Serial.println("4-####");  
 if (Rot>(cruise*0.8)) { steplevel=5;}  // Serial.println("5-#####");
 if (Rot>(cruise*0.9))   { steplevel=6;}  // Serial.println("6-######");  
 if (Rot>cruise)         { steplevel=7;}   // Serial.println("7-#######");  Wheel speed at 100% video speed
 if (Rot>(cruise*1.1))   { steplevel=8;}  // Serial.println("8-########");
 if (Rot>(cruise*1.2))   { steplevel=9;}  // Serial.println("9-#########");  
 if (Rot>(cruise*1.3))   { steplevel=10;} // Serial.println("10-##########");
 if (Rot>(cruise*1.4))   { steplevel=11;} // Serial.println("11-###########");
 if (Rot>(cruise*1.5))   { steplevel=12;} // Serial.println("12-############");
 if (Rot>(cruise*1.6))   { steplevel=13;} // Serial.println("13-#############");
 if (Rot>(cruise*1.7))   { steplevel=14;} // Serial.println("14-##############");
 if (Rot>(cruise*1.8))   { steplevel=15;} // Serial.println("15-###############");
 if (Rot>(cruise*1.9))   { steplevel=16;} // Serial.println("16-################");
 if (Rot>(cruise*2))     { steplevel=17;} // Serial.println("16-################"); Wheel speed at 200% video speed

 while (videostep<steplevel && steplevel<17) // adjust video speed by stepping controler to the right, (step up speed)                      
 {
   videostep = videostep +1;
   Keyboard.press('6'); delay(100); Keyboard.releaseAll(); delay(100);
 }

 while (videostep>steplevel&&steplevel>0)// adjust video speed by stepping controler to the left, (step down speed)
 {
   videostep = videostep -1;
   Keyboard.press('4'); delay(100); Keyboard.releaseAll(); delay(100);
 }                          
 
}

void rpm ()      //This is the function that the interupt calls
{
 bike_wheel_rev++;
 delay(100);
}

/[Code]

[/code]

Nick Gammon

Your post has got smiley faces and stuff like that in it.

Please edit your post, select the code, and put it between [code] ... [/code] tags.

You can do that by hitting the # button above the posting area.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy