From d8bd352df25c7d5a90b1384693a408a5a56ceedf Mon Sep 17 00:00:00 2001 From: jango27 <66255217+Shivansh2703@users.noreply.github.com> Date: Sun, 13 Nov 2022 15:55:27 -0500 Subject: [PATCH] Add files via upload --- testtrack_code.ino | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 testtrack_code.ino diff --git a/testtrack_code.ino b/testtrack_code.ino new file mode 100644 index 0000000..97d9c6a --- /dev/null +++ b/testtrack_code.ino @@ -0,0 +1,53 @@ + + +int SensorPin = 2; +int OutputPin = 13; + +int act_length = 10; +int disk_radius = 20; +int act_radius;; +int prot_radius; +int disk_circumference = 2 * 3.14 * disk_radius; + +int paper_angle = (act_length / disk_circumference) * 360; +int ang_velocity = 0; +int rpm = 0; + +void setup() { + pinMode(OutputPin, OUTPUT); + pinMode(SensorPin, INPUT); + Serial.begin(9600); +} + +void loop() { + int SensorValue = digitalRead(SensorPin); + + delay(10); + if (SensorValue==LOW){ // LOW MEANS Object Detected + int timer_var = 0; + //start timer + while (SensorValue == LOW) + { + SensorValue = digitalRead(SensorPin); + delay(10); + } + //stop timer + ang_velocity = paper_angle / timer_var; + rpm = ang_velocity / 6; + // display rpm + } + else + { + int timer_var = 0; + //start timer + while (SensorValue == HIGH) + { + SensorValue = digitalRead(SensorPin); + delay(10); + } + //stop timer + ang_velocity = paper_angle / timer_var; + rpm = ang_velocity / 6; + // display rpm + } +}