Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions testtrack_code.ino
Original file line number Diff line number Diff line change
@@ -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
}
}