Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

arduino /* PUSH UP COUNTER An ultrasonic sensor measures the distance between you and your head, if the distance is larger than 20 cm a

arduino

/* PUSH UP COUNTER

An ultrasonic sensor measures the distance between you and your head, if the distance is larger than 20 cm a rgb-led will shine red, if the distance is between 10 and 20 cm, it turns yellow and if it is less than 10 cm it turns green, and a point appears on a lcd screen. Every ten pushups it makes a sound. You can reset the score with the push of a button. */ #include // include LCD library

#define BLUE 12 // define RGB-led pins #define RED 10

const int trigPin = 8; //set pins for the ultrasonic sensor, button and buzzer const int echoPin = 9; const int buttonPin = A0; const int b = 13;

long duration; // set integers int distance; int i; int buttonState = 0; int x = 1; int y = 1;

LiquidCrystal lcd(6, 7, 2, 3, 4, 5); // set lcd pins

void setup() { Serial.begin(9600); // begin in 9600 baud pinMode(trigPin, OUTPUT); //set pin modes pinMode(echoPin, INPUT); pinMode(buttonPin, INPUT); pinMode(b, OUTPUT); pinMode(RED, OUTPUT); pinMode(BLUE, OUTPUT);

lcd.begin(16, 2); // begin lcd, define scale of lcd (16 places in a row, 2 rows) lcd.print("Push Ups:");

}

void loop() { digitalWrite(trigPin, HIGH); // send out an ultra sonic sound for 10 microseconds and measure the time it took for the sound to go from the trigpin to the echo pin delayMicroseconds(10); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distance = duration * 0.034/2; //convert the time the signal took to travel to distance in cm

if (distance >= 20) {digitalWrite(RED, HIGH); //configure RGB-led to burn red, magenta or blue depending on distance digitalWrite(BLUE, LOW);} if (distance <= 20) {digitalWrite(BLUE, HIGH);} if (distance <= 10) {digitalWrite(RED, LOW);}

if (i == (10 * y) && x == (1 * y)) { //this if statement plays a sound every ten pushups tone(b, 146.8); delay(50); noTone(b); delay(100); tone(b, 146.8); delay(50); noTone(b); delay(50); tone(b, 293.7); delay(100); noTone(b); x ++; y ++; } else if (distance <= 10) {delay(350);} //this if else statement makes sure that the time between pushup-readings always stay the same buttonState = digitalRead(buttonPin); //these lines of code resets every integer and the lcd to the original state by the press of a button if (buttonState == HIGH) { i = 0; x = 1; y = 1; lcd.setCursor(0,1); lcd.print("0 "); } lcd.setCursor(0, 1); // set cursor on the second row if (distance <= 10 ) {i ++;} //print a point if a pushup has been done lcd.print(i,DEC); while (distance <= 10) { //if the distance stays smaller then ten for a while, this piece of code makes sure that only one point is given for one pushup digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distance = duration * 0.034/2; delay(100);} } please i need use interupts confgration and time confgration for this code

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Analytics And Quality Management Fundamental Tools

Authors: Joseph Nguyen

1st Edition

B0CNGG3Y2W, 979-8862833232

More Books

Students also viewed these Databases questions

Question

1. What are the peculiarities of viruses ?

Answered: 1 week ago

Question

Describe the menstrual cycle in a woman.

Answered: 1 week ago