Show Posts
Pages: [1]
1  Using Arduino / Project Guidance / Re: Analog Read on: November 19, 2012, 08:14:18 pm
Thanks hazards thats basically what that code does. I thought I explained it alright so ill just figure it out on my own. Thanks for the replies
2  Using Arduino / Project Guidance / Analog Read on: November 19, 2012, 07:00:24 pm
I have been having trouble figuring out how to write the code to read a total amount drop in an analog signal. My sensor is 0-5volts and it works from 74-718 (0-100% position). I use smoothing normally but i took it out of my example code to get to my point.  I am trying to figure out how to read a specific amount of drop in voltage within a specific amount of time to light an led. Both voltage drop and time are variables cause it will get tuned in once I can get it to actually work. If anyone could direct me to a better way of doing this and or how I should go about figuring it out it would be very helpful. Thank you for your time
Code:
int SET, FALL=180, deb=30;
unsigned long cm,pm,pm1,pm2,pm3;

int LED=13;

void setup() {
   pinMode(A0, INPUT);
   pinMode(LED, OUTPUT);
   
}
void loop() {
  int APPS=analogRead(A0);
  cm=millis();
 
  if(APPS>SET){SET=APPS;pm=0;pm1=0;pm2=0;}
    if(APPS<SET){pm1=cm;}else{SET=APPS;pm1=0;}
    if(cm-pm1<deb){}else{
      if(APPS<SET-FALL){pm2=cm;}else{SET=APPS;pm1=0;}}
    if(cm-pm2<deb){}else{
      if(APPS<SET-FALL){digitalWrite(LED, HIGH);pm=cm;SET=285;}else{SET=APPS;pm=0;pm1=0;pm2=0;}}
  if(cm-pm<250){}else{digitalWrite(LED, LOW);pm=0;}
Pages: [1]