0% found this document useful (0 votes)
60 views

Interactive C Function Notes: Alloff Alloff

This document provides summaries of interactive C functions for controlling motors, reading sensors, playing tones, and more. Some key functions include alloff() to turn off all motors, analog() to read sensor values, beep() to play a tone, motor() to control a motor's power, and printf() for printing text to the screen. The document also explains formatting codes for printing different data types.

Uploaded by

gdayanand4u
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views

Interactive C Function Notes: Alloff Alloff

This document provides summaries of interactive C functions for controlling motors, reading sensors, playing tones, and more. Some key functions include alloff() to turn off all motors, analog() to read sensor values, beep() to play a tone, motor() to control a motor's power, and printf() for printing text to the screen. The document also explains formatting codes for printing different data types.

Uploaded by

gdayanand4u
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

Interactive C Function Notes

HB alloff: <void> () void alloff()


Turns off all motors. ao is a short form for alloff.

HB analog: <int> (<int>) int analog(int p)


Returns value of sensor port numbered p. Result is integer between 0 and 255. If the analog() function is applied to a port that is implemented digitally in hardware then the value 255 is returned if the hardware digital reading is ! (as if a digital switch is open and the pull up resistors are causing a high reading) and the value 0 is returned if the hardware digital reading is 0 (as if a digital switch is closed and pulling the reading near ground). "orts are numbered as mar#ed. $ote that ports !%&22 are floating so without a sensor inserted the value cannot be predicted.

HB ao: <void> () void ao()


Turns off all motors.

HB atan: float (<float>) float atan(float angle)


Returns arc tangent of angle. 'ngle is specified in radians( result is in radians.

HB beep: <void> () void beep()


"roduces a tone of 500 )ert* for a period of 0.+ seconds. Returns when the tone is finished.

HB beeper_off: <void> () void beeper_off()


Turns off the beeper.

HB beeper_on: <void> () void beeper_on()


Turns on the beeper at last fre,uency selected by the former function. The beeper remains on until the beeper_off function is e-ecuted.

HB b : <void> (<int>) void b (int !)


Turns motor m on in the bac#ward direction. .-ample/ b (")#

HB clear_digital_out: <int> (<int>) HB cos: float (<float>) float cos(float angle)


Returns cosine of angle. 'ngle is specified in radians( result is in radians.

HB defer: <void> () void defer()


0a#es a process swap out immediately after the function is called. 1seful if a process #nows that it will not need to do any wor# until the ne-t time around the scheduler loop. defer() is implemented as a 2 built&in function.

HB digital: <int> (<int>) int digital(int p)


Returns the value of the sensor in sensor port p as a true3false value (! for true and 0 for false). 4ensors are e-pected to be active low meaning that they are valued at *ero volts in the active or true state. Thus the library function returns

Page 1 of 6

the inverse of the actual reading from the digital hardware/ if the reading is *ero volts or logic *ero the digital() function will return true.

HB disable_encoder: <void> (<int>) void disable_encoder(int encoder)


5isables the given encoder and prevents it from counting. .ach shaft encoder uses processing time every time it receives a pulse while enabled so they should be disabled when you no longer need the encoder6s data.

HB enable_encoder: <void> (<int>) void enable_encoder(int encoder)


.nables the given encoder to start counting pulses and resets its counter to *ero. 7y default encoders start in the disabled state and must be enabled before they start counting.

HB e$p"%: float (<float>) float e$p"%(float nu!)


Returns !0 to the num power.

HB e$p: float (<float>) float e$p(float nu!)


Returns e to the num power.

HB fd: <void> (<int>) void fd(int !)


Turns motor ! on in the forward direction. .-ample/ fd(&)#

HB 'og_processor: <void> () void 'og_processor()


'llocates an additional 25% milliseconds of e-ecution to the currently running process. If this function is called repeatedly the system will wedge and only e-ecute the process that is calling 'og_processor(). 8nly a system reset will unwedge from this state. $eedless to say this function should be used with e-treme care and should not be placed in a loop unless wedging the machine is the desired outcome.

HB init_e$pbd_servos: <int> (<int>) HB ill_process: void (<int>) int ill_process(int pid)#


The ill_process function is used to destroy processes. "rocesses are destroyed by passing their process I5 number to ill_process. If the return value is 0 then the process was destroyed. If the return value is ! then the process was not found. The following code shows the main process creating a chec#9sensor process and then destroying it one second later/ void !ain() ( int pid# pid) start_process(c'ec _sensor(*))# sleep(".%)# ill_process(pid)# +

HB

nob: <int> () int nob()


Returns a value from 0 to 255 based on the position of a potentiometer. 8n the %.2:0 board the potentiometer is labelled frob nob.

HB log"%: float (<float>) float log"%(float nu!)


Returns logarithm of num to the base !0.

Page 2 of 6

HB log: float (<float>) float log(float nu!)


Returns natural logarithm of num.

HB !otor: <void> (<int>, <int>) void !otor(int !, int p)


Turns on motor ! at power level p. "ower levels range from !00 for full on forward to &!00 for full on bac#ward.

HB !seconds: long () long !seconds()


Returns the count of system time in milliseconds. Time count is reset by hardware reset (i.e. pressing reset switch on board) or the function

reset_s-ste!_ti!e(). !seconds()
function).

is implemented as a 2 primitive (not as a library

HB !sleep: <void> (<long>) void !sleep(long !sec)


;aits for an amount of time e,ual to or greater than msec milliseconds. msec is a long integer. .-ample/ 3< wait for !.5 seconds <3 !sleep(".%%/)# HB off: <void> (<int>) void off(int !) Turns off motor !. .-ample/ off(")# po0eroff: <void> () prg!_button: <int> () HB printf: void (<c'ar12>, ...)

/C3 4creen 5rinting


I2 has a version of the 2 function printf for formatted printing to the =25 screen. The synta- of printf is the following/ printf(for!at6string, 1arg6"2 , ... , 1arg6N2 ) This is best illustrated by some e-amples.

5rinting 7$a!ples
7$a!ple ": 5rinting a !essage. The following statement prints a te-t string to the screen. printf(>)ello world?@n>)# In this e-ample the format string is simply printed to the screen. The character @n at the end of the string signifies end-of-line. ;hen an end&of&line character is printed the =25 screen will be cleared when a subse,uent character is printed. Thus most printf statements are terminated by a @n. 7$a!ple *: 5rinting a nu!ber. The following statement prints the value of the integer variable - with a brief message. printf(>Aalue is Bd@n>, $)# The special form Bd is used to format the printing of an integer in decimal format. 7$a!ple &: 5rinting a nu!ber in binar-. The following statement prints the value of the integer variable - as a binary number. printf(>Aalue is Bb@n>, $)# The special form Bb is used to format the printing of an integer in binary format. 8nly the low byte of the number is printed. 7$a!ple 8: 5rinting a floating point nu!ber. The following statement prints the value of the floating point variable n as a floating point number. printf(>Aalue is Bf@n>, n)# The special form Bf is used to format the printing of floating point number.

Page 3 of 6

7$a!ple .: 5rinting t0o nu!bers in 'e$adeci!al for!at. printf(>'CB- 7CB-@n>, a, b)# The form B- formats an integer to print in he-adecimal.

For!atting Co!!and 4u!!arFor!at Co!!and 3ata 9-pe 3escription :d int 3eci!al nu!ber :$ int He$adeci!al nu!ber :b int /o0 b-te as binar- nu!ber :c int /o0 b-te as ;4CII c'aracter :f float Floating point nu!ber :s <c'ar C'aracter arra- (string) 4pecial Notes The final character position of the =25 screen is used as a system >heartbeat.> This character continuously blin#s between a large and small heart when the board is operating properly. If the character stops blin#ing the board has failed. 2haracters that would be printed beyond the final character position are truncated. ;hen using a two&line display the printf() command treats the display as a single longer line. "rinting of long integers is not presently supported.

HB rando!: <int> (<int>) HB read_encoder: <int> (<int>) int read_encoder(int encoder)


Returns the number of pulses counted by the given encoder since it was enabled or since the last reset whichever was more recent.

HB reset_encoder: <void> (<int>) void reset_encoder(int encoder)


Resets the counter of the given encoder to *ero. Dor an enabled encoder it is more efficient to reset its value than to use enable_encoder() to clear it.

HB reset_s-ste!_ti!e: <void> () void reset_s-ste!_ti!e()


Resets the count of system time to *ero milliseconds.

HB seconds: <float> () float seconds()


Returns the count of system time in seconds as a floating point number. Resolution is one millisecond.

HB set_beeper_pitc': <void> (<float>) void set_beeper_pitc'(float fre=uenc-)


4ets the beeper tone to be fre,uency )*. The subse,uent function is then used to turn the beeper on.

HB set_digital_out: <int> (<int>) HB sin: float (<float>) HB sleep: <void> (<float>) void sleep(float sec)
;aits for an amount of time e,ual to or slightly greater than sec seconds. 4ec is a floating point number. .-ample/ 3< wait for !.5 seconds <3 sleep("..)#

HB sonar: <int> ()

Page 4 of 6

HB s=rt: float (<float>) float s=rt(float nu!)


Returns s,uare root of num.

Page 5 of 6

HB start_button: <int> () int start_button()


Returns value of button labelled 4tart (or 7scape). .-ample/ 3< wait for button to be pressed( then wait for it to be released so that button press is debounced <3 0'ile (>start_button()) (+ 0'ile (start_button()) (+

HB start_press: <void> () void start_press()


=i#e stop_press() but for the 4tart button.

HB stop_button: <int> () int stop_button()


Returns value of button labelled 4top (or C'oose)/ ! if pressed and 0 if released. .-ample/ 3< wait until stop button pressed <3 0'ile (>stop_button()) (+

HB stop_press: <void> () void stop_press()


;aits for the 4top button to be pressed then released. Then issues a short beep and returns. The code for stop_press() is as follows/ 0'ile (>stop_button())# 0'ile (stop_button())# beep()#

HB _s-ste!_print_off: <void> () HB _s-ste!_print_on: <void> () HB _s-ste!_p0!_off: <void> () HB _s-ste!_p0!_on: <void> () HB tan: float (<float>) float tan(float angle)
Returns tangent of angle. 'ngle is specified in radians( result is in radians.

HB test_digital_out: <int> (<int>) HB tone: <void> (<float>, <float>) void tone(float fre=uenc-, float lengt')
"roduces a tone at pitch fre,uency )ert* for length seconds. Returns when the tone is finished. 7oth fre,uency and length are floats.

Page 6 of 6

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy