Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Servo TextLCD mbed ultra
try.cpp
- Committer:
- Andres0131
- Date:
- 2018-05-18
- Revision:
- 1:1452468e1e49
- Parent:
- 0:faeefad8239f
File content as of revision 1:1452468e1e49:
#include "mbed.h"
#include "Servo.h"
#include "TextLCD.h"
#include "hcsr04.h"
int angle (int);
HCSR04 usensor(D8,D9);
TextLCD lcd( D0,D1, D2, D3, D4, D5,TextLCD::LCD16x2);
unsigned int dist;
int main() {
int angle1;
Servo Servo1(D15);
Servo1.Enable(1500,20000);
while(1) {
for (int pos = 0; pos < 2000; pos += 11) {
lcd.locate(0,0);
Servo1.SetPosition(pos);
angle1 = angle(pos);
lcd.cls();
lcd.printf("Angle=%d",angle1, "DEG");
printf ("%d", angle1);
printf (",");
printf ("%d", dist);
printf (".");
usensor.start();
wait_ms(0);
dist=usensor.get_dist_cm();
lcd.locate(0,1);
lcd.printf("cm:%ld",dist );
wait_ms(10);
}
for (int pos = 2000; pos > 0; pos -= 11) {
lcd.locate(0,0);
Servo1.SetPosition(pos);
angle1 = angle(pos);
lcd.cls();
lcd.printf("Angle=%d",angle1 , "DEG");
printf ("%d", angle1);
printf (",");
printf ("%d", dist);
printf (".");
usensor.start();
wait_ms(0);
dist=usensor.get_dist_cm();
lcd.locate(0,1);
lcd.printf("cm:%ld",dist );
wait_ms(10);
}
}
}
int angle (int pos)
{
int angle = (pos / 11 );
return angle;
}