FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects
Commit a246d2d2 authored by ayush1301's avatar ayush1301
Browse files

Metal detect

parent 3e66a8d0
No related branches found
No related tags found
No related merge requests found
...@@ -43,6 +43,11 @@ float US_distance_avg; ...@@ -43,6 +43,11 @@ float US_distance_avg;
//Metal Detector //Metal Detector
int metal_detector = 1; int metal_detector = 1;
int metal_float_counter = 0;
#define metal_floating_avg_num 100
float metal_avg = 0;
float metal_vals[metal_floating_avg_num] = {0};
//Servo //Servo
#define servo_position 180 #define servo_position 180
...@@ -217,6 +222,8 @@ void update_IR_vals() { ...@@ -217,6 +222,8 @@ void update_IR_vals() {
void update_metal_detector() { void update_metal_detector() {
unsigned long new_val = pulseIn(metal_detector, HIGH); unsigned long new_val = pulseIn(metal_detector, HIGH);
float new_val_Hz = 1000.0/new_val;
metal_avg = floating_average(&metal_float_counter, metal_vals, metal_avg, new_val_Hz, metal_floating_avg_num);
} }
void check_push_button(Adafruit_DCMotor *motors[]) { void check_push_button(Adafruit_DCMotor *motors[]) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment