Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Pre lab: There are two parts to the prelab: one is code writing, the other is to

ID: 3349344 • Letter: P

Question

Pre lab: There are two parts to the prelab: one is code writing, the other is to determine the number of grid points and the time to measure at each grid point. Here is the pseudo code for the microcontroller. Write the code and print it out as your prelab. Have the code ready to use in the lab: Set up DIO3 as input Set up serial connection with computer Time to count (some number of milli-seconds, more than 1 less than 32,000) Main loop: Print "Press space bar to start counting... While (no bytes from computer) wait 10ms Clear buffer by reading string Print "counting with line feed Set Counter 0 To = number of milliseconds(see below) While (Number of millseconds -To)

Explanation / Answer

#define PULSE_PIN 3
#define PULSE_TYPE HIGH
#define PULSE_TIMEOUT 10000 //vary this value to change timeout of pulse detection
unsigned long int t0,t2c=5000; // vary t2c variable to change time for which sampling has to be done
void setup() {
// put your setup code here, to run once:
pinMode(PULSE_PIN,INPUT); //setting DIO3 as input
Serial.begin(9600); //Setting up serial connection with computer
}

void loop() {
// put your main code here, to run repeatedly:
Serial.println("Press space bar to start counting...");
while(!Serial.available()); //wait for data to arrive
delay(10); //wait 10ms
Serial.readString(); //read string to clear UART buffer
Serial.println("Counting");
unsigned long int counter=0;
t0=millis();
while((millis()-t0)<t2c)
if(pulseIn(PULSE_PIN,PULSE_TYPE,PULSE_TIMEOUT)) counter++; //increase counter if is pulse detected
Serial.println(counter); //print final counter value
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote