What I'm trying to do is get some code to take an analogue reading from sensor (got that) and turn on a motor once it reaches a certain limit (got that too).
But what I NEED it to do, is wait a second after it takes the reading, and then if the reading stays above the threshold I set, the motor should turn on for one second, and then stop, and not act for full minute before doing it again.
There's no point reading the code I put it, because it's simple if statements, analogRead and digitalWrite to get the basics. I know I need to do a LOT more than that, and it's making my brain fizzle. I've tried the Blink Without Delay example, and it became an utter mess. I have pretty much no idea what I'm doing once I head into it. I've spent longer than I should at it, and I'm completely at a loss. Any help would be GREATLY appreciated.
I'll put up the code anyways.
What I have now;
#include <MeetAndroid.h>
MeetAndroid meetAndroid;
int sensor = A5;
int motor = A3;void setup()
{
Serial.begin(115200);pinMode(sensor, INPUT);
pinMode(motor, OUTPUT);
}
void loop()
{
if (analogRead(A5) > 800)
digitalWrite(A3, HIGH);
else digitalWrite(A3, LOW);meetAndroid.receive();
// read input pin and send result to Android
meetAndroid.send(analogRead(sensor));delay(100);
}
And what I tried to get to work. Doesn't work <_<
#include <MeetAndroid.h>
MeetAndroid meetAndroid;
int sensor = A5;
int motor = 7;
const int ledPin = 13;
int ledState = LOW;
long previousMillis = 0;
long interval = 100;void setup()
{
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
pinMode(sensor, INPUT);
pinMode(motor, OUTPUT);
}
void loop()
{
if (analogRead(A5) > 800)
digitalWrite(7, HIGH);
if (analogRead(A5) < 750)
digitalWrite(7, LOW);unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
previousMillis = currentMillis;
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
digitalWrite(ledPin, ledState);
meetAndroid.receive();
meetAndroid.send(analogRead(sensor));}
}
Even I can see, the second one is just a mess and makes no sense at all.
So you see. I'm pretty lost.
Thanks in advance, guys!
Edit: It's also running a bit of code to send the sensors reading to an Android app that will graph out the measurement. That hasn't caused problems so far, I think. I hope. It never did before, anyway, regardless or where I stuck it in. Maybe it is the problem.
It, and it's code and Arduino examples, can be found on http://www.amarino-toolkit.net/ if you're wondering about it.