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.

misc varsi n t f l a g = 0 , o l d f l a g = 0 , count = 0 ;unsigned long time , t1 ;double f r e q =0;// runs at r e s e tvoid s e t u p ( ) {// high output r a t e ( bps )S e r i a l . b e g i n ( 5 0 0 0 0 0 ) ;pinMode ( motor1 , OUTPUT) ;pinMode ( motor2 , OUTPUT) ;}void l o o p ( ) {d i g i t a l W r i t e ( motor1 , HIGH ) ; // s t a r t one motori n t s e n s o r V a l u e = analogRead (A0 ) ; // read analog pin 0// save o l d v a l u e f o r comparisono l d f l a g = f l a g ;// check i f c r o s s e si f ( s e n s o r V a l u e > t h r e s h o l d )f l a g = 1 ;e l s ef l a g = 0 ;// 9 f l a g s 4 w a v e l e n g h t si f ( f l a g != o l d f l a g ){i f ( count == 0){time = m i c r o s ( ) ;count++;}e l s e i f ( count == 8){t1 = m i c r o s ()− time ;f r e q = 240000000.0/(( double ) t1 ) ;S e r i a l . p r i n t l n ( f r e q ) ;count = 0 ;}e l s e{count++;}}// sendPlotData (” v o l t a g e ” , sensorValue ) ;16

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

Saved successfully!

Ooh no, something went wrong!