|
本帖最后由 hinghui88 于 24-3-2017 11:53 AM 编辑
我本身刚刚认识了Arduino这东西,是从一位来公司做实习的外国实习生。
但是Project还没完成他因为私人的事离开了马来西亚。
现在,我只剩下一个Arduino和LED Display。
我请教了很多人,但是他们都没办法回答我的问题,希望这边的大神现身解答。
我有一个Arduino和他的Code。
const int SonarPin1 = A0;
const int SonarPin2 = A2;
const int SonarPin3 = A4;
const int SonarPin4 = A6;
const int SonarPin5 = A8;
const int SonarPin6 = A9;
const int SonarPin7 = A11;
const int SonarPin8 = A13;
#define txPin 14
#define rxPin 15
void setup() {
// initialize serial communication:
Serial.begin(9600);
}
void loop()
{
long duration, duration1, duration2, duration3, duration4, duration5, duration6, duration7, duration8;
long parking = 8;
// first sensor
duration1 = analogRead(SonarPin1)/2;
duration2 = analogRead(SonarPin2)/2;
duration3 = analogRead(SonarPin3)/2;
duration4 = analogRead(SonarPin4)/2;
duration5 = analogRead(SonarPin5)/2;
duration6 = analogRead(SonarPin6)/2;
duration7 = analogRead(SonarPin7)/2;
duration8 = analogRead(SonarPin8)/2;
if(duration1 < 8)
parking--;
if(duration2 < 8)
parking--;
if(duration3 < 8)
parking--;
if(duration4 < 8)
parking--;
if(duration5 < 8)
parking--;
if(duration6 < 8)
parking--;
if(duration7 < 8)
parking--;
if(duration8 < 8)
parking--;
Serial.print("number of empty Spaces: "
Serial.print(parking);
Serial.print("\n"
delay(100);
}
long microsecondsToInches(long microseconds)
{
// According to Parallax's datasheet for the PING))), there are
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
// second). This gives the distance travelled by the ping, outbound
// and return, so we divide by 2 to get the distance of the obstacle.
// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}
和一个LED Display,我要怎样把Arduino收到的Information,寄出Serial Command去LED?
Supplier说:把"B101"放进去就行了...
|
|