戴在手上的测距仪

作品图

嗯,就这样。可以掰弯戴在手臂上,测出前方距离。至于戴在手上的样子,请自行脑补~

接线图

接线图

有点乱。。。

嗯,还有程序:

 

#include<U8glib.h>
U8GLIB_SSD1306_128X64 u8g(10, 9, 12, 11, 13);

const int TrigPin = 7;
const int EchoPin = 8;
unsigned int distance;

void setup() {

pinMode(TrigPin, OUTPUT);
pinMode(EchoPin, INPUT);

u8g.setColorIndex(1); // pixel on

}

void loop() {
digitalWrite(TrigPin, LOW);
delayMicroseconds(2);
digitalWrite(TrigPin, HIGH);
delayMicroseconds(10);
digitalWrite(TrigPin, LOW);

distance = pulseIn(EchoPin, HIGH) / 58.00;

u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );

delay(100);
}

void draw(void) {
u8g.setFont(u8g_font_ncenB24);
//u8g.setFont(u8g_font_osb21);
u8g.drawStr( 80, 50, “cm”);

u8g.setPrintPos(5, 50);
u8g.print(distance);

}

这里需要一个U8GLIB库。没法上传,要做的童鞋自己找一下吧

 

 

 

Advertisements

2 thoughts on “戴在手上的测距仪

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s