Question
Ultrasound sensor HC-SR04 Convert this Energia code for EK-TM4C123GXL launchpad to Code Composer #define echoPin PD_0 #define trigPin PC_4 #define BUTTON_PIN PF_0 void setup() {
Ultrasound sensor HC-SR04
Convert this Energia code for EK-TM4C123GXL launchpad to Code Composer
#define echoPin PD_0 #define trigPin PC_4 #define BUTTON_PIN PF_0
void setup() { // put your setup code here, to run once: Serial.begin(115200); pinMode(BUTTON_PIN, INPUT_PULLUP);
while (digitalRead(2));
pinMode(echoPin, INPUT); pinMode(trigPin, OUTPUT);
}
void loop() { // put your main code here, to run repeatedly: long duration, distance; digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distance = duration/50; if (distance > 255) { distance = 255; } //Serial.write(distance); Serial.println(distance); delay(50); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started