Académique Documents
Professionnel Documents
Culture Documents
//22/05/2017
//
//
//
//PURPOSE:
//
//
//DEFINES Region:
//Defines or setups up various constant values and Arduino pin numbers used by
the sensor and the display
#define GREENDISTANCE 30
#define AMBERDISTANCE 10
#define REDDISTANCE 5
//define Ultrasonic sensor module pins here - this is the pins that the sensor is
connected to on the Arduino board.
#define UVCC 10
#define UTRIG 11
#define UECHO 12
#define UGND 13
//define LED module pins here - this is the pins that the sensor is connected to on
the Arduino board.
//LED module is a RGB type module so that various colours can be displayed by
the one module.
#define LEDPLUS 3
#define LEDBLUE 0
#define LEDRED 1
#define LEDGREEN 2
//SETUP Region:
//The setup() method is ran once just after the Arduino is powered up.
void setup()
usonicsetup();
ledsetup();
//The loop() method runs continuously after the Arduino has started and has
been initialiseds.
//The loop() section is were you place any code you want to run over and over
again.
void loop()
void ledsetup()
pinMode(LEDPLUS, OUTPUT);
digitalWrite(LEDPLUS, HIGH);
pinMode(LEDRED, OUTPUT);
digitalWrite(LEDRED, HIGH);
pinMode(LEDGREEN, OUTPUT);
digitalWrite(LEDGREEN, HIGH);
pinMode(LEDBLUE, OUTPUT);
digitalWrite(LEDBLUE, HIGH);
g=!g;
b=!b;
digitalWrite(LEDGREEN, g);
digitalWrite(LEDBLUE, b);
void usonicsetup(void)
pinMode(UGND, OUTPUT);
digitalWrite(UGND, LOW);
pinMode(UVCC, OUTPUT);
digitalWrite(UVCC, HIGH);
pinMode(UECHO, INPUT); //ECHO pin is input
digitalWrite(UTRIG, LOW);
long b;
delay(1);
digitalWrite(UTRIG, LOW);
long utimer=micros();
utimer=micros();
while((digitalRead(UECHO)==HIGH)&&((micros()-utimer)<utimeout)){} //wait
for pin state to change
b=micros()-utimer;
return b;