Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define DW digitalWrite
- #define PM pinMode
- #define H HIGH
- #define L LOW
- #define OP OUTPUT
- #define SB Serial.begin
- int pins[3] = {A1,A2,A3};
- float duration, distance;
- void setup() {
- PM(pins[0],OP);
- PM(pins[1],INPUT);
- PM(pins[2], OP);
- SB(9600);
- }
- void loop() {
- DW(pins[0],L);
- delay(2);
- DW(pins[0],H);
- delayMicroseconds(10);
- DW(pins[0],L);
- duration = pulseIn(pins[1],H);
- distance = (duration * 0.034 * 0.5);
- if(distance<=100){
- DW(pins[2],H);
- }else{
- DW(pins[2],L);
- }
- delay(500);
- }
Advertisement
Add Comment
Please, Sign In to add comment