13.07.2015 Views

Project paper - The Department of Physics and Astronomy

Project paper - The Department of Physics and Astronomy

Project paper - The Department of Physics and Astronomy

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

8 Appendix: Code/∗B l i n k i n gmotorsListing 1: ”Blink Flow”This s c r i p t turn one ouput high , then the o t h e r with a d e l a y o f 1 second .∗/// Pin 13 has an LED connected on most Arduino boards .// g i v e i t a name :// Output pins are 4 <strong>and</strong> 12i n t out1 = 4 ;i n t out2 = 1 2 ;// i n t = 13;// the s e t u p r o u t i n e runs once when you p r e s s r e s e t :void s e t u p ( ) {// i n i t i a l i z e the d i g i t a l pin as an output .pinMode ( out1 , OUTPUT) ;pinMode ( out2 , OUTPUT) ;}// the loop r o u t i n e runs over <strong>and</strong> over again f o r e v e r :void l o o p ( ) {d i g i t a l W r i t e ( out2 ,LOW) ;d i g i t a l W r i t e ( out1 , HIGH ) ; // turn the LED on (HIGH i s the v o l t a g e l e v e l )d e l a y ( 3 0 0 0 0 ) ; // wait f o r 10 secondsd i g i t a l W r i t e ( out1 , LOW) ; // turn the LED o f f by making the v o l t a g e LOWd i g i t a l W r i t e ( out2 , HIGH ) ;d e l a y ( 3 0 0 0 0 ) ; // wait f o r 10 seconds}Listing 2: ”Read Speed from Sensor”/∗ Read Analog Voltage o f one motor <strong>and</strong> p r i n t s frequency o fs i g n a l from analog i n p u t to s e r i a l v i a MegunoLink∗/// d i g i t a l output pins o f the two DC motor r e l a y c o n t r o l si n t motor1 = 4 ;i n t motor2 = 1 2 ;// middle o f v o l t a g e s i g n a l f o r frequency readingi n t t h r e s h o l d = 3 5 ;15

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!