an ultrasonic sensor used as a car sensor

Dependencies:   N5110 PowerControl beep mbed sensor

Embed: (wiki syntax)

« Back to documentation index

main.cpp File Reference

main.cpp File Reference

Program implementation. More...

Go to the source code of this file.

Functions

int main ()
void buttonPressed ()
 when the button is pressed this action is called
void welcomeMessage ()
 Print welcome message.
void getDistanceCm ()
 gets the distance in cm by dividing 10 read values by 10
void getDistanceIn ()
 gets the distance in inches by dividing 10 read values by 10
void getDistanceUs ()
 gets the distance in us by dividing 10 read values by 10
void compDist ()
 used to compare the distances
void distanceA ()
 compares the cases of each distance to set the Led's values and the buzzer

Detailed Description

Program implementation.

Definition in file main.cpp.


Function Documentation

void buttonPressed (  )

when the button is pressed this action is called

when button is pressed it will check if i >1

if it is it will set it to 0

if not it will increment i by one

Definition at line 34 of file main.cpp.

void compDist (  )

used to compare the distances

looks for where the range of the reading is to set its conditions

calls this action to show the reading

each character is 6 pixels wide, screen is 84 pixels (84/6 = 14)

print formatted data to buffer

if string will fit on display

clears LCD

sets 2 rectangles

prints distance and the reading below it

refreshes LCD screen

compares distances and sets them in their specified range

sets case

sets case

sets case

sets case

sets case

sets case

calls this action to show the reading

each character is 6 pixels wide, screen is 84 pixels (84/6 = 14)

print formatted data to buffer

if string will fit on display

clears LCD

sets 2 rectangles

prints distance and the reading below it

refreshes LCD screen

compares distances and sets them in their specified range

sets case

sets case

sets case

sets case

sets case

sets case

calls this action to show the reading

each character is 6 pixels wide, screen is 84 pixels (84/6 = 14)

print formatted data to buffer

if string will fit on display

clears LCD

sets 2 rectangles

prints distance and the reading below it

refreshes LCD screen

compares distances and sets them in their specified range

sets case

sets case

sets case

sets case

sets case

sets case

Definition at line 202 of file main.cpp.

void distanceA (  )

compares the cases of each distance to set the Led's values and the buzzer

See also:
This code was from a library I found

case 1 would have 2 LED's on

See also:
This code was from a library I found

case 3 would have 4 LED's on

See also:
This code was from a library I found

case 4 would have 5 LED's on

See also:
This code was from a library I found

case 5 would have 6 LED's on

See also:
This code was from a library I found

Definition at line 362 of file main.cpp.

void getDistanceCm (  )

gets the distance in cm by dividing 10 read values by 10

Returns:
the average distance in cm

adds up 10 distances read by the sensor

there is a 70 ms delay between each reading

all of them are added to the sum

the sum is divided by 10 to get the average

Definition at line 132 of file main.cpp.

void getDistanceIn (  )

gets the distance in inches by dividing 10 read values by 10

Returns:
the average distance in inches

adds up 10 distances read by the sensor

there is a 70 ms delay between each reading

all of them are added to the sum

the sum is divided by 10 to get the average

Definition at line 158 of file main.cpp.

void getDistanceUs (  )

gets the distance in us by dividing 10 read values by 10

Returns:
the average distance in us

adds up 10 distances read by the sensor

there is a 70 ms delay between each reading

all of them are added to the sum

the sum is divided by 10 to get the average

Definition at line 180 of file main.cpp.

int main (  )

the Ethernet cable is powered down

the LCD display is initialised when switch is on

the welcome message will appear

event generated on rising edge

sets a variable to change as the pot is changing

sets the brightness to the pot value

compares the distance to set it in a specific range

Definition at line 12 of file main.cpp.

void welcomeMessage (  )

Print welcome message.

Shows the welcome message when the LCD is on.

bottom left rectangle is set

bottom right rectangle is set

bottom middle rectangle is set

is set over the bottom rectangles

circle is set on bottom middle box

big middle box is set over everything

top black rectangle is set

left middle black rect is set

middle black rect is set

right middle black rect is set

left bottom black rect is set

middle bottom black rect is set

right bottom black rect is set

rectangle is set over big middle box

left top black rect is set

top black rect is set

right top black rect is set

left bottom black rect is set

middle bottom black rect is set

right bottom black rect is set

rectangle under triangle is set

left line to complete triangle

right line to complete triangle

clears intersecting lines from rectangle

gets the distance after the message

Definition at line 50 of file main.cpp.