Skip to content

Instantly share code, notes, and snippets.

@abdul-rehman-2050
Last active December 12, 2017 18:29
Show Gist options
  • Save abdul-rehman-2050/4d2556d8a17e0fbdd24dba51c29b7d37 to your computer and use it in GitHub Desktop.
Save abdul-rehman-2050/4d2556d8a17e0fbdd24dba51c29b7d37 to your computer and use it in GitHub Desktop.
#include <Average.h>
#define WINDOW_SIZE 30
#define IR_REC_PIN A0
int ref_val = 0;
Average<int> an_buff(30);
int calibrate()
{
int i=0;
an_buff.clear();
for(i=0;i<WINDOW_SIZE;i++)
{
an_buff.push(analogRead(IR_REC_PIN));
delay(10);
}
return an_buff.mode();
}
void setup() {
Serial.begin(9600);
delay(1000);
Serial.println("Ready...");
pinMode(13,OUTPUT);
}
int dt=0;
void loop()
{
int s_val = analogRead(A0);
float cent_val =(3.3 * analogRead(A1) * 100.0) / 1024;
s_val = map(s_val,0,1023,0,50);
if(s_val>25)
{
digitalWrite(13,HIGH);
dt=0;
}
else if(s_val<15)
{
dt++;
if(dt>4)
digitalWrite(13,LOW);
}
Serial.println(s_val);
delay(20);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment